Ask A Question

Notifications

You’re not receiving notifications from this thread.

Question regarding the threaded comments! Post titles or link_to post only if the current user is on another users show page.

Alex asked in Rails

Hey there all, Would anyone know how you could go about linking to the commented on post? For example if you had a view on the users views for comments.. Listing all the comments by the user how would I attach the post title or link to the post?

Reply

If you link to the page the post is on, you can set the anchor in the link to to scroll down to the comment.

For example, your post here has an anchor on it:

https://gorails.com/forum/question-regarding-the-threaded-comments-post-titles-or-link_to-post-only-if-the-current-user-is-on-another-users-show-page#forum_post_16256

You would link to post_path(comment.post, anchor: dom_id(comment)) which is basically what I'm doing, but mine are called forum threads and forum posts here on GoRails.

Reply

I get
undefined method `post' for #Comment:0x00007fb5e5880930

When i try to add a link_to in my _comment partial.

Basically the way i have it setup in the users show page, I've created a comments view /user/comments/id
it works

it links to the comments partial grabbing all the users comments on the application, the problem spans when i want to just link to the post.

<%= link_to post_path(comment.post) %>
in my partial

i just have <%= render @comments %> in the users comments html.erb.

in my users controller i have

def comments
@user = User.find_by_username(params[:id])
@comments = @user.comments.order('created_at DESC')
end

Am i on the right path here? Or complete off route. That you Chris

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,110+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.