lib/active_admin/router.rb in activeadmin-0.4.4 vs lib/active_admin/router.rb in activeadmin-0.5.0.pre

- old
+ new

@@ -12,18 +12,26 @@ # Application.routes.draw do |map| # ActiveAdmin.routes(self) # end # def apply(router) - # Define any necessary dashboard routes + # Define any necessary dashboard routes and root router.instance_exec(@application.namespaces.values) do |namespaces| namespaces.each do |namespace| + root_and_dashboard_routes = Proc.new do + root :to => (namespace.root_to || "dashboard#index") + if ActiveAdmin::Dashboards.built? + match '/dashboard' => 'dashboard#index', :as => 'dashboard' + end + end + if namespace.root? - match '/' => 'dashboard#index', :as => 'dashboard' + instance_eval &root_and_dashboard_routes else - name = namespace.name - match name.to_s => "#{name}/dashboard#index", :as => "#{name.to_s}_dashboard" + namespace(namespace.name) do + instance_eval &root_and_dashboard_routes + end end end end # Now define the routes for each resource @@ -33,11 +41,11 @@ # Define the block the will get eval'd within the namespace route_definition_block = Proc.new do case config when Resource - resources config.underscored_resource_name.pluralize do + resources config.resource_name.route_key, :only => config.defined_actions do # Define any member actions member do config.member_actions.each do |action| # eg: get :comment send(action.http_verb, action.name) @@ -47,13 +55,16 @@ # Define any collection actions collection do config.collection_actions.each do |action| send(action.http_verb, action.name) end + + post :batch_action end end when Page + match "/#{config.underscored_resource_name}" => "#{config.underscored_resource_name}#index" config.page_actions.each do |action| match "/#{config.underscored_resource_name}/#{action.name}" => "#{config.underscored_resource_name}##{action.name}", :via => action.http_verb end else @@ -68,18 +79,27 @@ # If its optional, make the normal resource routes instance_eval &routes_for_belongs_to if config.belongs_to_config.optional? # Make the nested belongs_to routes # :only is set to nothing so that we don't clobber any existing routes on the resource - resources config.belongs_to_config.target.underscored_resource_name.pluralize, :only => [] do + resources config.belongs_to_config.target.resource_name.plural, :only => [] do instance_eval &routes_for_belongs_to end + + # Batch action path is not nested. + if config.is_a?(Resource) + resources config.resource_name.route_key, :only => config.defined_actions do + collection do + post :batch_action + end + end + end end end # Add on the namespace if required - if !config.namespace.root? + unless config.namespace.root? routes_in_namespace = route_definition_block.dup route_definition_block = Proc.new do namespace config.namespace.name do instance_eval(&routes_in_namespace) end @@ -88,8 +108,7 @@ instance_eval &route_definition_block end end end - end end