All threads / Question regarding the threaded comments! Post titles or link_to post only if the current user is on another users show page.
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?

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.

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

Join the discussion

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

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

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

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.