问题
I don't get why this return me a error
<%= form_for(@user), :html => {:class => 'form-connexion'} do |f| %>
<%= render 'shared/error_messages' %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirm Password" %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Save changes", class: "btn btn-large btn-primary" %>
<% end %>
D:/xxxxxxx/app/views/users/edit.html.erb:7: syntax error, unexpected =>, expecting keyword_end ...end= form_for(@user), :html => {:class => 'form-connexion'}... ... ^
D:/xxxxxxx/app/views/users/edit.html.erb:7: syntax error, unexpected keyword_do_block, expecting keyword_end ...{:class => 'form-connexion'} do |f| @output_buffer.safe_appe... ... ^
D:/xxxxxxx/app/views/users/edit.html.erb:29: syntax error, unexpected keyword_ensure, expecting end-of-input
I'm using the same syntax in another file and it's ok.
回答1:
form_for(@user), :html => ...
That end bracket, after @user
, closes the call for the method #form_for
, so it doesn't know what to do with the comma and then the hash.
Change that to:
form_for(@user, :html => ...) do |f|
And you'll be good. Or even no brackets:
form_for @user, :html => ... do |f|
来源:https://stackoverflow.com/questions/25557044/class-to-form-for-ruby-on-rails