Rails: Nested resources conflict, how to scope the index action depending on the called route

前端 未结 4 1297
走了就别回头了
走了就别回头了 2021-02-13 19:50

Imagine you have two defined routes:

map.resources articles
map.resources categories, :has_many => :articles

both accessible by helpers/path

4条回答
  •  旧时难觅i
    2021-02-13 20:28

    if params[:category_id].blank?
      # all
    else
      # find by category_id
    end
    

    I like to consider the action independent from the route. No matter how they get there, make a reasonable decision as to what to do.

提交回复
热议问题