Class to form_for Ruby on Rails

允我心安 提交于 2019-12-13 07:47:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!