title: Rails form partial rendering of one model in the view of another model
body: <p>I am working on building a rails app and right now I am struggling with displaying a from partial from one model in the view of another model. </p>
  
  <p>So I have models <code>User</code> and <code>Goal</code>.  A user can have many goals, and a goal has one user.</p>
  
  <p>In the show view for a <code>User</code>, I list out that user's goals.  I am trying to display a jQuery dialog that allows you to edit the goal.  I have a form_for partial for the goal that I modified based on initial scaffolding</p>
  
  <pre><code>&lt;%= form_for([@user, @goal]) do |f| %&gt;
  ...
  &lt;% end %&gt;
  </code></pre>
  
  <p>I am trying to create a <code>&lt;div&gt;</code> in the <code>users#show</code> view that can render that form, but I can't figure out how (or if it is even possible) to pass the correct parameters to the form_for partial</p>
  
  <pre><code>&lt;%= div_for(goal, :class =&gt; "dialog edit", :title =&gt; "Edit Goal") do %&gt;
     &lt;%= render :partial =&gt; 'goals/form' %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>which gives me <code>undefined method 'model_name' for NilClass</code> error, leading me to believe that the form_for doesn't know what @user and @goal should be.</p>
  
  <p>My controller for the user#show is like so</p>
  
  <pre><code>def show
     @user = User.find(params[:id])
  end
  </code></pre>
  
  <p>and for goals#edit</p>
  
  <pre><code>def edit
     @goal = @user.goals.find(params[:id])
  end
  </code></pre>
  
  <p>Routes looks like this</p>
  
  <pre><code>resources :users do
     resources :goals
  end
  </code></pre>
  
  <p>What do I need to adjust to display the edit goal form in the <code>user#show</code> view?</p>