This more advanced episode will show you how to dynamically generate named routes by adding a method to the map object.
Update: there’s now a plugin which does this called static_actions.
Update: there’s now a plugin which does this called static_actions.
# routes.rb
ActionController::Routing::Routes.draw do |map|
def map.controller_actions(controller, actions)
actions.each do |action|
self.send("#{controller}_#{action}", "#{controller}/#{action}", :controller => controller, :action => action)
end
end
map.resources :products, :categories
map.controller_actions 'about', %w[company privacy license]
end
本文介绍了一种在Ruby on Rails中通过自定义方法动态生成命名路由的方法。这种方法允许开发者为控制器的动作创建特定的路由,增强了应用程序的灵活性。此外,还提到了一个名为static_actions的插件,该插件可以实现相同的功能。
3858

被折叠的 条评论
为什么被折叠?



