Using a partial inside a form_for tag

I have the following:

<% form_for @user do |f| -%>

<%= render :partial => “relationship_status” %>

<% end -%>

How do I pass f to the partial! :slight_smile: Or can I not do that?

Just pass the form to the partial as a 'local' like this:

<%= render :partial => "relationship_status" %, :locals => {:form =>
f } %>

You can then refer to the form in your partial like this:

<%= form.text_field ... %>

Are you sure that you need to? If you are rendering relationship info
for the user, but that relationship info relies on some other model,
you might be able to:

<% fields_for :relationships, relationships do |fld| %>
<% fld.text_field ... %>
<% end %>

and pass the user into the partial:

render :partial=>'relationship_status', :locals=>{:relationships=>user.relationships}

The main point being that if you're rendering a partial that displays
fields for a different model then you don't need to pass the form
variable, but a reference to that model or collection.