I have Comment as a polymorphic model.
It is attached to Post, Review, etc.
I also have an action in CommentsController, called test
.
I
I decided to just use an if statement in the view, based on if the current action was present, such as if @post or if @review
The correct way to do this is with polymorphic_url...
Something like this: (in your partial view)
@commentable.each |commentable|
test_#{commentable.class.to_s.downcase}_comment_path
end
if it is 'post' then it will generate 'test_post_comment_path', if it is review, it will generate test_review_comment_path
Just use two different paths?
What I mean is: you don't want to put so much logic inside routes.
If routes try to do something more than routing, the first time somethings goes wrong you'll be in serious trouble.
In your partial view, the logic to create specific links or other html comment stuff should go in a helper.