Note that there are some explanatory texts on larger screens.

plurals
  1. PORails form partial rendering of one model in the view of another model
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload