Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As you can see, the <code>proposition_id</code> parameter is empty, so your controller can't find the proposition unless you give it a valid id.</p> <p>You need to make sure your <code>new</code> form sends the <code>proposition_id</code> attribute. One way to do this is:</p> <ol> <li><p>Set the proposition in the <code>new</code> action in the controller: <code>@micropost.proposition = ...</code></p></li> <li><p>In the form, add a hidden field for the id: <code>f.hidden_field :proposition_id</code></p></li> <li><p>In the <code>create</code> action, find the appropriate Proposition with <code>params[:micropost][:proposition_id]</code></p></li> </ol> <p>(You'll also want to make sure to use <code>attr_accessible</code> in your Micropost model, and make sure <code>proposition_id</code> is NOT in that list. Otherwise, you'll be open to nasty security holes. See <a href="http://www.kalzumeus.com/2010/09/22/security-lessons-learned-from-the-diaspora-launch/" rel="nofollow noreferrer">http://www.kalzumeus.com/2010/09/22/security-lessons-learned-from-the-diaspora-launch/</a> and <a href="https://stackoverflow.com/questions/4651579/which-fields-should-be-protected-from-mass-assignment">Which fields should be protected from mass assignment?</a>)</p> <p>EDIT (due to comment):</p> <p>Your new action should be like this:</p> <pre><code>def new @micropost = Micropost.new @micropost.proposition_id = params[:proposition_id] </code></pre> <p>This is slightly different from what is said above, and is due to the fact you're sending the proposition id in the request to <code>new</code>. There's no need to look up the actual proposition record, since we're only interested in the <code>id</code> field (which we already have).</p>
 

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