Note that there are some explanatory texts on larger screens.

plurals
  1. PORails won't save my foreign key to the database
    primarykey
    data
    text
    <p>So basically I have two models, Entry and Comment. I have the association setup so that Entry has many Comments:</p> <pre><code>class Entry &lt; ActiveRecord::Base has_many :comments end </code></pre> <p>And a comment belongs to an entry:</p> <pre><code>class Comment &lt; ActiveRecord::Base belongs_to :entry end </code></pre> <p>In my database schema I have setup the comments table with a column called entry_id. To my knowledge, this is all I needed to do to setup an association. <strong>However when I save a comment, it does not save the entry_id into the database.</strong></p> <p>I can confirm that the entry_id is being passed in the form. Here is a dump of the params variable being sent to the controller.</p> <pre><code>{"comment"=&gt;{"comment"=&gt;"ghgghgh"}, "commit"=&gt;"Create Comment", "format"=&gt;"", "entry_id"=&gt;"1", "authenticity_token"=&gt;"G4uH8smdA2eeKeTXbD9NbenKH4AbWLyJuPWQzRcn6CI=", "utf8"=&gt;"✓"} </code></pre> <p>Any Ideas?</p> <p>EDIT: This is my view with the comment form built in:</p> <pre><code>&lt;% @entry.each do |e| %&gt; &lt;div class="entry"&gt; &lt;p&gt;&lt;%= e.entry %&gt;&lt;/p&gt; &lt;small&gt;Posted by &lt;%= e.author %&gt; at &lt;%= e.created_at.strftime("%I:%M%p %m/%d/%Y") %&gt;&lt;/small&gt; &lt;% if e.comments.nil? %&gt; &lt;p&gt;No Comments&lt;/p&gt; &lt;% else %&gt; &lt;% e.comments.each do |c| %&gt; &lt;blockquote&gt;&lt;%= c.comment %&gt;&lt;/blockquote&gt; &lt;% end %&gt; &lt;% end %&gt; &lt;%= form_for @comment, :url =&gt; entry_comments_path(e, @comment) do |f| %&gt; &lt;%= f.label :comment %&gt; &lt;%= f.text_area :comment %&gt; &lt;%= f.submit %&gt; &lt;% end %&gt; &lt;/div&gt; &lt;hr /&gt; &lt;% end %&gt; &lt;%= button_to "Write A Message", new_entry_path, :method =&gt; :get %&gt; </code></pre> <p>I have commments as a nested route:</p> <pre><code> resources :entries do resources :comments end </code></pre>
    singulars
    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.
 

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