#78 √ resolved
Michael Hartl

People should be able to delete wall comments they make

Reported by Michael Hartl | May 23rd, 2008 @ 05:33 PM | in Miscellaneous polish

Facebook added this, and I like it: wall owners can of course delete wall comments, but so can the commenters. This helps alleviate 'commenter regret', which I had on a wall comment at Facebook. I was grateful to be able to delete it.

Comments and changes to this ticket

  • Jesse Crockett

    Jesse Crockett June 2nd, 2008 @ 03:43 PM

    Does this come close?

    <li>
      <div class="profile-image">
        <%= image_link(comment.commenter, :image => :thumbnail) %>
        <%= image_tag "icons/comment.gif", :class => "icon" %>
      </div>
      <p class="meta published">
        <%= person_link comment.commenter %> said
        <%= time_ago_in_words(comment.created_at) %> ago
      </p>
      <%= display comment.body %>
    
    # 
      <%- if current_person?(comment.commentable) || current_person?(comment.commenter) -%>
    #
      <br />
      <%= link_to "delete", person_comment_path(@person, comment),
                            :method => :delete %>
      <%- end -%>  
    </li>
    
  • Michael Hartl

    Michael Hartl June 17th, 2008 @ 04:54 PM

      • → Milestone changed from “” to “Miscellaneous polish”
  • Jorge Dias

    Jorge Dias June 24th, 2008 @ 08:12 AM

    Hey jesse and michael! Is anyone of you working on this ticket? If not I'll do it

  • Jesse Crockett

    Jesse Crockett June 24th, 2008 @ 09:32 AM

    I'm still checking out the updates.

  • Jesse Crockett

    Jesse Crockett June 25th, 2008 @ 12:42 PM

      • → Tag changed from “” to “enhancement”

    Jorge, you're more than welcome and encouraged to work on this ticket in full force. As for Michael, silence == consent :-)

  • Jesse Crockett

    Jesse Crockett July 31st, 2008 @ 03:57 PM

    I'm puzzled. The following code, respectively in app/views/posts/_comment and app/views/people/_comment, does not work at all. Take away the if statement, the delete link appears, but does not work. Mainly I don't understand the usage of 'commentable'. Can you give me a hint?

      <%- if current_person?(comment.commentable.blog.person) -%>
      <div>
        <br />
        <%= link_to "delete", blog_post_comment_path(@blog, @post, comment),
                              :method => :delete %>
      </div>
      <%- end -%>
    
    #
    ##
    #
    
      <%- if current_person?(comment.commentable) -%>
      <br />
      <%= link_to "delete", person_comment_path(@person, comment),
                            :method => :delete %>
      <%- end -%>
    
  • Jesse Crockett

    Jesse Crockett July 31st, 2008 @ 04:20 PM

    Successfully delted a wall comment with this code in app/views/people/_comment

      <%- if current_person?(comment.commenter) -%>
      <br />
      <%= link_to "delete", person_comment_path(comment.commenter, comment),
                            :method => :delete %>
      <%- end -%> 
    

    Changing person_comment_path(@person, comment) to the above.

    But, this does not work in app/views/posts/_comment

     <%= link_to "delete", blog_post_comment_path(@blog, @post, comment),
                              :method => :delete %>
    
  • Jesse Crockett

    Jesse Crockett July 31st, 2008 @ 04:40 PM

    Okay, the exact same method works in both cases, using `person_comment_path(comment.commenter, comment)'

    but it redirects to the user profile. Otherwise, you've got the functionality required by the ticket, in the above snippet for app/views/people/_comment.

    Do you want it to redirect to the person's profile? Is this okay, or should I work on that?

    Thanks.

  • Jesse Crockett

    Jesse Crockett July 31st, 2008 @ 05:03 PM

      def destroy
        @comment = Comment.find(params[:id])
        @comment.destroy
    
        respond_to do |format|
          flash[:success] = "Comment deleted"
          format.html { redirect_to :back }
        end
      end
    

    changing `redirect_to comments_url' to the above.

    I hope this is well enough. If nothing's wrong, I'll write the tests.

  • Michael Hartl

    Michael Hartl July 31st, 2008 @ 06:12 PM

    Looks about right. Go ahead and write the tests and we'll know for sure.

  • Jesse Crockett

    Jesse Crockett July 31st, 2008 @ 07:13 PM

    thanks for the note..

    after googling around, I find that the following clears `rake spec' while maintaining `redirect_to :back' functionality.

    app/controllers/comments_controller

      def destroy
        @comment = Comment.find(params[:id])
        @comment.destroy
    
        respond_to do |format|
          flash[:success] = "Comment deleted"
          format.html { request.env["HTTP_REFERER"] ? (redirect_to :back) :
             (redirect_to home_url) }
        end
      end
    

    spec/controllers/comments_controller_spec

        it "should require the correct user to destroy a comment" do
          login_as @commenter
          comment = comments(:blog_comment)
          delete :destroy, :blog_id => @blog, :post_id => @post, :id => comment
          response.should redirect_to(home_url)
        end
    

    and again for the wall comments. It might be ugly, but it seems to work.

    I'll figure out how to make a pull request, unless something's wrong here. thanks

  • Jesse Crockett

    Jesse Crockett July 31st, 2008 @ 07:57 PM

    Git is intimidating atm, but I ran the installation shell script again, changed the files and ran `git push' then requested a pull to user 'insoshi'. Let me know if there are any problems. thanks!

  • Steven Fines

    Steven Fines September 2nd, 2008 @ 10:26 PM

    Does this patch need additional work or testing - It seems like there's not been activity on it for a few weeks

  • Michael Hartl

    Michael Hartl September 3rd, 2008 @ 11:52 AM

    I'm still working through a pull request backlog. It's on my list, though.

  • Michael Hartl

    Michael Hartl September 5th, 2008 @ 11:35 AM

      • → Assigned user changed from “” to “Michael Hartl”
      • → State changed from “new” to “open”
  • Michael Hartl

    Michael Hartl September 5th, 2008 @ 11:44 AM

      • → State changed from “open” to “resolved”

    This was a little trickier than it looked. There's a weird redirect to Comments#show if you (1) post a comment and (2) immediately delete it. Though it raises an exception, the page still renders! Despite mighty effort, I was unable to find the source of the problem, so I punted by adding a redirect_to in Comments#show.

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins