title: Rails 3 linking into a nested polymorphic resource
body: <p>I am trying out a commenting system in a way described by ryanb in <a href="https://github.com/railscasts/154-polymorphic-association/tree/master/revised/blog-after" rel="nofollow">https://github.com/railscasts/154-polymorphic-association/tree/master/revised/blog-after</a>.</p>
  
  <p>It uses Rails 3 nested resource routing seen in <a href="https://github.com/railscasts/154-polymorphic-association/blob/master/revised/blog-after/config/routes.rb" rel="nofollow">routes.rb</a>:</p>
  
  <pre><code>resources :articles do
    resource :comments
  end
  </code></pre>
  
  <p>Comments are loaded by parents type and id as seen in <a href="https://github.com/railscasts/154-polymorphic-association/blob/master/revised/blog-after/app/controllers/articles_controller.rb" rel="nofollow">articles_controller.rb</a> and <a href="https://github.com/railscasts/154-polymorphic-association/blob/master/revised/blog-after/app/controllers/comments_controller.rb" rel="nofollow">comments_controller.rb</a>:</p>
  
  <pre><code>class ArticlesController &lt; ApplicationController
    ...
    def show
      @article = Article.find(params[:id])
      @commentable = @article
      @comments = @commentable.comments
      @comment = Comment.new
    end
  
  class CommentsController &lt; ApplicationController
    before_filter :load_commentable
  
    def index
      @comments = @commentable.comments
    end
    ...
  private
  
    def load_commentable
      resource, id = request.path.split('/')[1, 2]
      @commentable = resource.singularize.classify.constantize.find(id)
    end
    ...
  end
  </code></pre>
  
  <p>How would I go about adding a link to a comments edit or destroy actions in comments' view template?</p>
  
  <p><a href="https://github.com/railscasts/154-polymorphic-association/blob/master/revised/blog-after/app/views/comments/_comments.html.erb" rel="nofollow">_comments.html.erb:</a></p>
  
  <pre><code>&lt;% @comments.each do |comment| %&gt;
    &lt;div class="comment"&gt;
      &lt;%= simple_format comment.content %&gt;
      &lt;%= link_to "Delete", comment, method: :delete %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>