title: polymorphic association without nested routes event
body: <p>I have 2 models article and forums which have polymorphic association with comments model.</p>
  
  <p>I am using simple routes as follows.</p>
  
  <p><strong>routes.rb</strong> :</p>
  
  <pre><code>resources :articles 
  resources :comments
  resources :forums 
  </code></pre>
  
  <p>following is my <strong>models code for article and forum</strong> :</p>
  
  <pre><code>has_many :comments, :as =&gt; :commentable,:dependent =&gt; :destroy
  </code></pre>
  
  <p>in <strong>comments model</strong> :</p>
  
  <pre><code>belongs_to :commentable, :polymorphic =&gt; true
  </code></pre>
  
  <p>now when i enter <code>http://localhost:3000/articles/10</code></p>
  
  <p>it shows article content and below that previous comments on this article and a textarea to give new comments but when i click on create comments it goes to this url <code>http://localhost:3000/comments</code> and i get following error</p>
  
  <pre><code>undefined method `comments' for nil:NilClass
  </code></pre>
  
  <p>following is my <strong>comments controller code</strong> :</p>
  
  <pre><code>def create
    @commentable = find_commentable
    @comment = @commentable.comments.new(params[:comment])
  
    if @comment.save
      flash[:notice] = "Successfully saved comment."
      redirect_to(articles_url, :notice =&gt; 'Articlecmnt was successfully created.')
    else
      render :action =&gt; 'new'
    end
  end
  
  def new
    @comment = Comment.new 
  end
  
  def find_commentable
    params.each do |name, value|
      if name =~ /(.+)_id$/
        return $1.classify.constantize.find(value)
      end
    end
    nil
  end
  </code></pre>
  
  <p>following is my <strong>index.html.erb</strong> file code which i am rendering in articles and forums <code>show.html.haml</code> using  <code>= render :template=&gt;"comments/index"</code></p>
  
  <pre><code>&lt;% form_for [@commentable, Comment.new] do |form| %&gt;
  
    &lt;table&gt;
      &lt;tr&gt;
        &lt;td&gt;&lt;%= form.text_area :commentcontent, :rows =&gt; 5 %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= form.hidden_field :user_id, :value =&gt; @current_user.id %&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;&lt;%= submit_tag "Add comment" %&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;/table&gt;
  
  &lt;% end %&gt;
  
  &lt;ul id="comments"&gt;
    &lt;% @comments.each do |comment| %&gt;
    &lt;li&gt;
      &lt;p&gt;
        &lt;b&gt;Posted &lt;%= time_ago_in_words(comment.created_at) %&gt; ago&lt;/b&gt;
      &lt;/p&gt; 
      &lt;%= comment.commentcontent %&gt;&lt;b&gt; by &lt;%= @current_user.email %&gt;&lt;/b&gt;
    &lt;/li&gt;
  
    &lt;% end %&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>how to solve this error? I think its not getting correct <code>article_id</code>. how can I strore correct <code>commentable_id</code> and <code>commentable_type</code>(article or forum) when creating new comments? Is there any other way than this <code>find_commentable</code>?</p>
  
  <p>thanks in advance</p>