habe ich haben zwei Formen:Wie für 2 bildet teilweise zu bauen, die verschiedene URL-Pfade
<% provide(:title, "Edit user") %>
<h1>Update your profile</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages' %>
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
<%= f.label :email %>
<%= f.email_field :email, class: 'form-control' %>
<%= f.label :password %>
<%= f.password_field :password, class: 'form-control' %>
<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation, class: 'form-control' %>
<%= f.submit "Save changes", class: "btn btn-primary" %>
<% end %>
<div class="gravatar_edit">
<%= gravatar_for @user %>
<a href="http://gravatar.com/emails" target="_blank">change</a>
</div>
</div>
</div>
und
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(@user, url: signup_path) do |f| %>
<%= render 'shared/error_messages' %>
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
<%= f.label :email %>
<%= f.email_field :email, class: 'form-control' %>
<%= f.label :password %>
<%= f.password_field :password, class: 'form-control' %>
<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation, class: 'form-control' %>
<%= f.submit "Create my account", class: "btn btn-primary" %>
<% end %>
</div>
</div>
ich einen Teil erstellen müssen, was ich getan habe:
Aber es gibt ein Problem, dass Linien <%= form_for(@user) do |f| %>
und <%= form_for(@user, url: signup_path) do |f| %>
sind etwas anders - man übergibt eine URL an die für M Helfer der andere nicht.
Section 10.1.1 von Rails-Tutorial schlägt vor, es gibt eine Möglichkeit, es mit der provide
Methode ("Mein Vorschlag ist die Variable-Passing-Technik"), aber ich konnte es nicht finden. Ich habe versucht, <% provide(:link, signup_path)
und dann <%= form_for(@user, url: yield(:link)) do |f| %>
zu übergeben, aber es hat nicht funktioniert. This answer bot nicht die Lösung, nach der Hartl suchen würde.
Dank
Es funktioniert! Vielen Dank! – Pere