类到form_for Ruby on Rails [英] Class to form_for Ruby on Rails
本文介绍了类到form_for Ruby on Rails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不明白为什么这会给我一个错误
<%= 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,确认密码%>
<%= f.password_field:password_confirmation%>
<%= f.submit保存更改,class:btn btn-large btn-primary%&
<%end%>
D :/xxxxxxx/app/views/users/edit.html.erb:7:语法错误,unexpected =>,expecting keyword_end ... end = form_for(@user),:html => {:class => 'form-connexion'} ... ... ^
D:/xxxxxxx/app/views/users/edit.html.erb:7:语法错误,意外的keyword_do_block,expecting keyword_end ... {:class => 'form-connexion'} do | f | @ output_buffer.safe_appe ... ... ^
D:/xxxxxxx/app/views/users/edit.html.erb:29:语法错误,意外的keyword_ensure,期望输入结束
我在另一个文件中使用相同的语法,可以。
解决方案
form_for(@user),:html => ...
在 @user
,关闭对 #form_for
方法的调用,因此它不知道如何处理逗号和散列。
更改为:
form_for(@user,:html => ...)do | f |
你会很好。甚至没有括号:
form_for @user,:html => ... do | f |
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|
这篇关于类到form_for Ruby on Rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文