#79 Generate Named Routes

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.


# 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

你可能感兴趣的:(Routes)