简体   繁体   中英

Class to form_for Ruby on Rails

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.

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|

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM