Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is your find_commentable method.</p> <p>Here are the params passed to your CommentsController#create: </p> <pre><code>Started POST "/comments" for 127.0.0.1 at 2012-05-20 13:17:38 -0700 Processing by CommentsController#create as HTML Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"SOLcF71+WpfNLtpBFpz2qOZVaqcVCHL2AVZWwM2w0C4=", "comment"=&gt;{"text"=&gt;"Test this comment"}, "commit"=&gt;"Create Comment"} </code></pre> <p>Here is your CommentsController#create: </p> <pre><code>def create @commentable = find_commentable @comment = @commentable.comments.build(params[:comment]) #&lt;&lt;&lt;&lt;LINE 13 def find_commentable params.each do |name, value| if name =~ /(.+)_id$/ return $1.classify.constantize.find(value) end end nil end </code></pre> <p>As you can see, find_commentable expects a param like xx_id (for example, comments_id) which it uses to search for an appropriate class (in case of comments_id, it will be Comment), otherwise it returns nil. Refer <a href="http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-classify" rel="nofollow">classify and constantize</a> here.</p> <p>Your params do not contain any such param. So, you always get a nil object. </p> <p>Your find_commentable needs some rework. I think in case of nested_fields, it should be an expression like </p> <pre><code>/(.+)_attributes$/ </code></pre> <p>instead of </p> <pre><code>/(.+)_id$/. </code></pre> <p>And you need to have </p> <pre><code>:accepts_nested_attributes_for :commentable </code></pre> <p>in your Comment model class.</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.
    1. VO
      singulars
      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