simple_form_for具有相同对象的部分文件

时间:2013-04-26 14:05:56

标签: ruby-on-rails simple-form

我是ruby on rails的新手我有一个视图,在该部分文件中有部分文件,我也必须渲染相同的对象,但是我得到了错误。

这是我的代码

app/view/customer/_form.html.erb
 <%= simple_form_for(@customer) do |f| %> 
 <%= f.input :first_name, placeholder: 'First Name', label: 'Customer First Name' %>
 <%= f.input :last_name, placeholder: 'Last name', label: 'Customer Last Name' %>
 <%= f.input :email, placeholder: 'user@domain.com', label: 'Customer Email' %>
<%= render :partial=> other_fields,:f => f %>   
<%end%>

app/views/customer/_other_fields.html.erb

<%= f.input :user_name, label: 'User Name' %>
<%= f.input :password, label: 'Password' %>
<%= f.input :password_confirmation, :required => true %>

我收到错误

undefined local variable or method `f' for #  

2 个答案:

答案 0 :(得分:2)

<%= render :partial=> other_fields, :locals => {:f => f} %> 

答案 1 :(得分:0)

试试这个:

<%= render :partial=> other_fields, :object => @customer, :locals => {:f => f} %>