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

  • SEARCH
  • Home
  • 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 8490313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:04:44+00:00 2026-06-10T22:04:44+00:00

I am trying to destroy a comment through Ajax. In my app, my comment

  • 0

I am trying to destroy a comment through Ajax. In my app, my comment model uses a polymorphic association. The comment deletes successfully (in the database) using the code below. However, when I call the destroy.js.erb, it doesn’t do anything and I think the problem is that the dom_id doesn’t match the HTML id, so it is not updating. I think I am experiencing the same thing that @mu_is_too_short articulated in the answer to this question. I need help with how to solve this though. I do not know if the solution involves a) somehow passing the local variable comment to the destory.js.erb or b) another solution.

routes.rb

resources :feeds do
  resources :comments
end

destroy.js.erb

 $('#<%= dom_id(@comment) %>')
   .fadeOut ->
   $(this).remove()

_comment.html.erb

 <div id=<%= dom_id(comment) %> class="comment">
   <em>on <%= comment.created_at.strftime('%b %d, %Y at %I:%M %p') %></em>
   <%= link_to "Remove", [@commentable, comment], :method => :delete, :remote => true %>
   <%= simple_format comment.content %>
 </div>

feeds/show.html.erb

 <div id="comments">
    <%= render @comments %>
 </div>

Comments controller

 class CommentsController < ApplicationController

   def create
     @comment = @commentable.comments.new(params[:comment])
     if @comment.save
        respond_to do |format|
           format.html { redirect_to @commentable }
           format.js
        end
     else
        render :new
     end
    end

    def destroy
      @comment = Comment.find(params[:id])
      @commentable = @comment.commentable
        if @comment.destroy
          respond_to do |format|
            format.html { redirect_to @commentable }
            format.js
          end
        end
     end
  end

Feeds controller

 class FeedsController < ApplicationController
  def show
     @feed = Feed.find(params[:id])
     @commentable = @feed
     @comments = @commentable.comments
     @comment = Comment.new
   end
 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-10T22:04:45+00:00Added an answer on June 10, 2026 at 10:04 pm

    By the looks of it, @comment will contain a comment when you get to destroy.js.erb, as you set it in the controller immediately before that, so I do not think it has anything to do with the referenced answer. I wonder if this is being caused by the lack of quotes around your id here: <div id=<%= dom_id(comment) %> class="comment">… I suspect if you correct this, and any other relevant HTML validation errors, it will start working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to roll together two Railscasts: http://railscasts.com/episodes/262-trees-with-ancestry and http://railscasts.com/episodes/154-polymorphic-association on my app.
I'm trying to switch views in my app using this chunk of code: self->variable1
I'm trying to validate an attribute in one model when I destroy another model.
I am trying to test a CanCan ability in my app that also uses
I'm writing an application that uses GDB to access information through java. Using Runtime.getRuntime.exec,
I'm trying to make this be a link to a destroy action for a
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
I´m trying to make a User - Infos association where my User has_many Infos.
I am trying to do a simple test for my model Course , I
I am having an issue when trying to destroy an active record instance. It

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.