Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8917893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:36:25+00:00 2026-06-15T05:36:25+00:00

I am trying out a commenting system in a way described by ryanb in

  • 0

I am trying out a commenting system in a way described by ryanb in https://github.com/railscasts/154-polymorphic-association/tree/master/revised/blog-after.

It uses Rails 3 nested resource routing seen in routes.rb:

resources :articles do
  resource :comments
end

Comments are loaded by parents type and id as seen in articles_controller.rb and comments_controller.rb:

class ArticlesController < ApplicationController
  ...
  def show
    @article = Article.find(params[:id])
    @commentable = @article
    @comments = @commentable.comments
    @comment = Comment.new
  end

class CommentsController < 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

How would I go about adding a link to a comments edit or destroy actions in comments’ view template?

_comments.html.erb:

<% @comments.each do |comment| %>
  <div class="comment">
    <%= simple_format comment.content %>
    <%= link_to "Delete", comment, method: :delete %>
  </div>
<% end %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:36:28+00:00Added an answer on June 15, 2026 at 5:36 am

    With jdoes advice I looked more into the array passing and noticed routes.rb was missing an s from resources :comments. Fixed version:

      resources :articles do
        resources :comments do
        end
      end
    

    Now the template works perfectly just by giving the link as an array.

    <% @comments.each do |comment| %>
      <div class="comment">
        <%= simple_format comment.content %>
        <%= link_to "Delete", [@commentable, comment], method: :delete %>
      </div>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Commenting out stylesheets in HTML documents to support older browsers I'm trying
Seems like both EnyimMemcached ( https://github.com/enyim/EnyimMemcached ) and BeITMemcached ( http://code.google.com/p/beitmemcached/ ) are popular
I'm trying to make a commenting system like Stackoverflow has. The problem I'm facing
Trying out the example usage of codebrew rails-backbone , everything works fine but the
Trying out the examples found on pleac.sf.net , I'm not able to get an
Im trying out the banking sample application and when i try to add or
While trying out an experimental UINavigationController-based iPhone application, I ran into a problem when
After trying out VS2010b2 also my VS2008 installation changes the versions of solution and
Just trying out Hibernate (with Annotations) and I'm having problems with my mappings. I
im trying out paypals html api where you specify price, item_name, customer information and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.