title: Rails: Implementing an acts_as_commentable_with_threading form
body: <p>I'm trying to create a form that utilizes the acts_as_commentable_with_threading gem. Although I have working code, it's got a couple of kinks. My main concern is that I've had to make a hidden_field for the commentable object's id. I suspect there's a way to bypass this on account of the gem's build-in method, build_from. If you know how to do that, please share. At the moment, here's what my code looks like:</p>
  
  <p>In my Impressions controller I have:</p>
  
  <pre><code>@impression = @book.impressions.find_by_user_id(user)
  @new_comment = Comment.build_from( @impression, current_user.id, "" )
  </code></pre>
  
  <p>In my view, I have:</p>
  
  <pre><code>&lt;%= form_for @new_comment, :remote =&gt; true do |f| %&gt;
    &lt;%= f.text_area :body %&gt;
    &lt;%= f.hidden_field :commentable_id, :value =&gt; @impression.id %&gt;
    &lt;%= f.submit 'Submit' %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>And in the Comments controller I have:</p>
  
  <pre><code>def create
    @comment = Comment.build_from( Userimpression.find(params[:comment][:commentable_id]), current_user.id, params[:comment][:body] )
    @comment.save
  end
  </code></pre>
  
  <p>In the Comments model:</p>
  
  <pre><code>def self.build_from(obj, user_id, comment)
    c = self.new
    c.commentable_id = obj.id
    c.commentable_type = obj.class.base_class.name
    c.body = comment
    c.user_id = user_id
    c
  end
  </code></pre>