Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Couldn't find <object> without an ID"
    text
    copied!<p>I'm having problems implementing a kind of comments form, where comments (called "microposts") belong_to both users and posts, users have_many comments, and posts (called "propositions") have_many comments.</p> <p>My code for the comments form is:</p> <pre><code>&lt;%= form_for @micropost do |f| %&gt; &lt;div class="field"&gt; &lt;%= f.text_area :content %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit "Submit" %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>The MicropostsController has this in the create action:</p> <pre><code> def create @proposition = Proposition.find(params[:proposition_id]) @micropost = current_user.microposts.build(params[:micropost]) @micropost.proposition = @proposition if @micropost.save flash[:success] = "Contribution submitted" redirect_to root_path else @feed_items = [] render 'pages/home' end end </code></pre> <p>The form for creating a new micropost is on the same page as a proposition, yet the proposition id doesn't seem to get passed at any point.</p> <p>This is the error I get on submitting the micropost form:</p> <blockquote> <p>ActiveRecord::RecordNotFound in MicropostsController#create</p> <p>Couldn't find Proposition without an ID</p> </blockquote> <p>Parameters are:</p> <blockquote> <p>{"commit"=>"Submit", "micropost"=>{"proposition_id"=>"", "content"=>"First comment"}, "authenticity_token"=>"TD6kZaHv3CPWM7xLzibEbaLJHI0Uw43H+pq88HLZFjc=", "utf8"=>"✓"}</p> </blockquote> <p>I'm completely new to rails and very new to coding anything at all, so I'd be grateful for any help you can give me!</p> <p>Thanks in advance.</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