2

i am making nested form, like it was done in railscasts and have a problem with render. In my form i have

 <% 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 %>

and in my user_form file I have

<% 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 %>

I have an error in first line of partial

undefined local variable or method `f' for

what I am doing wrong?(I am using rails 2.3, but in cast rails 2 were used too). Thanks in advance

1
  • You are missing :locals => {...}. Two more advices: 1) use [:user, @question] as resource and you could skip the :url option. 2) Call fields_for outside the user partial, that improves modularity. Commented Jun 4, 2012 at 14:47

1 Answer 1

9

I think you may need to change

<%= render :partial => "user_form", :f => f %>

to one of the following:

<%= render "user_form", :f => f %>
<%= render :partial => "user_form", :locals => {:f => f} %>
Sign up to request clarification or add additional context in comments.

2 Comments

thanks :partial => "user_form", :locals => {:f => f} %> helped
Awesome! The shorter form will work in later versions of Rails -- I wasn't sure what version that was added.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.