Rails 4 [Best practices] Nested resources and shallow: true

后端 未结 5 1574
独厮守ぢ
独厮守ぢ 2020-12-28 15:44

The following post is based on Rails 4.

I am currently looking for a best-practice about the multiple nested resources (more than 1), and the option shallow: true.

5条回答
  •  爱一瞬间的悲伤
    2020-12-28 16:07

    From this answer it seems shallow routes somewhat defy the convention of Rails, IMO.

    I would think you wouldn't need the explicit path helper for a show route. The link_to helper should be able to infer it from the object's to_param method.

    #your helper becomes 
    link_to "show", collection
    

    If you use the helper your way as you have above you probably need to pass the nested ID of the parent resource to the helper too.

    link_to "show", collection_path([project, collection])
    

提交回复
热议问题