我正在制作嵌套形式,就像在 railscasts 中完成的那样,但渲染有问题。 在我的表格中,我有
<% form_for @question, :url => user_questions_path, :html => {:multipart => true} do |f| %>
<%= f.label :name %>
<%= f.text_field :name, :class => "text_input" %>
<%= f.label :description %>
<%= f.text_area :description, :cols => "1", :rows => "1", :class => "textarea" %>
<div id="reg">
<%= render :partial => "user_form", :f => f %>
</div>
...
<% end %>
在我的 user_form 文件中有
<% f.fields_for :user do |builder| %>
<%= builder.label :email %>
<%= builder.text_field :email, :class => "text_input" %>
<%= builder.label :password %>
<%= builder.text_field :password, :class => "text_input" %>
<%= builder.label :password_confirmation %>
<%= builder.text_field :password_confirmation, :class => "text_input" %>
<% builder.fields_for :user_profile, @question.user.user_profile || @question.user.build_user_profile do |u| %>
<%= u.label :secondname %>
<%= u.text_field :secondname, :class => "text_input" %>
<%= u.label :firstname %>
<%= u.text_field :firstname, :class => "text_input" %>
<% end %>
<% end %>
我在部分的第一行有错误
undefined local variable or method `f' for
我做错了什么?(我使用的是 rails 2.3,但也使用了 cast rails 2)。 提前致谢
最佳答案
我想你可能需要改变
<%= render :partial => "user_form", :f => f %>
以下之一:
<%= render "user_form", :f => f %>
<%= render :partial => "user_form", :locals => {:f => f} %>
关于ruby-on-rails - 通过渲染传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10883114/