Polymorphic Routes in Rails - in views

前端 未结 4 851
执念已碎
执念已碎 2021-01-15 03:19

I have Comment as a polymorphic model.

It is attached to Post, Review, etc.

I also have an action in CommentsController, called test.

I

4条回答
  •  一整个雨季
    2021-01-15 03:49

    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

提交回复
热议问题