Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有两个控制器apple,banana并且我想根据 url 动态分配它们。例如,我想做类似的事情
apple
banana
match 'eat/:fruit' => ':fruit#eat'
在我的routes.rb. 我希望当我访问 url 时eat/apple,rails 会使用apple#eat. 否则,rails 将使用banana#eatfor eat/banana。
routes.rb
eat/apple
apple#eat
banana#eat
eat/banana
有什么办法吗?
来自http://guides.rubyonrails.org/routing.html#bound-parameters
我认为这会起作用:
match ':action/:controller'