Dynamic Rails routes based on database models

后端 未结 4 2074
忘掉有多难
忘掉有多难 2020-12-15 12:57

So I\'m building a Rails site that needs routes based on two different types

I have a Language model and a Category model

So I need to be able to go to a la

4条回答
  •  遥遥无期
    2020-12-15 13:25

    Two routes get '/:language' and get '/:category' are exactly same for rails. Rails router can't differentiate between /books and /ruby. In both cases rails would just look for a route in routes.rb which looks something like /something, it will pick the first match and dispatches the route to the specified controller's action.

    In your case,

    all the requests with /something format

    would be matched to

    get '/:language', to: "top_voted#language"

提交回复
热议问题