class ActiveAdmin::Resource::Routes::RouteBuilder
Attributes
resource[R]
Public Class Methods
new(resource)
click to toggle source
# File lib/active_admin/resource/routes.rb, line 36 def initialize(resource) @resource = resource end
Public Instance Methods
collection_path(params)
click to toggle source
# File lib/active_admin/resource/routes.rb, line 40 def collection_path(params) route_name = route_name( resource.resources_configuration[:self][:route_collection_name], suffix: (resource.route_uncountable? ? "index_path" : "path") ) routes.public_send route_name, *route_collection_params(params) end
edit_instance_path(instance)
click to toggle source
@return [String] the path to the edit page of this resource @param instance [ActiveRecord::Base] the instance we want the path of @example “/admin/posts/1/edit”
# File lib/active_admin/resource/routes.rb, line 61 def edit_instance_path(instance) path = resource.resources_configuration[:self][:route_instance_name] route_name = route_name(path, action: :edit) routes.public_send route_name, *route_instance_params(instance) end
instance_path(instance)
click to toggle source
@return [String] the path to this resource collection page @param instance [ActiveRecord::Base] the instance we want the path of @example “/admin/posts/1”
# File lib/active_admin/resource/routes.rb, line 52 def instance_path(instance) route_name = route_name(resource.resources_configuration[:self][:route_instance_name]) routes.public_send route_name, *route_instance_params(instance) end
Private Instance Methods
belongs_to_name()
click to toggle source
# File lib/active_admin/resource/routes.rb, line 105 def belongs_to_name resource.belongs_to_config.target.resource_name.singular if nested? end
nested?()
click to toggle source
# File lib/active_admin/resource/routes.rb, line 101 def nested? resource.belongs_to? && resource.belongs_to_config.required? end
route_collection_params(params)
click to toggle source
# File lib/active_admin/resource/routes.rb, line 95 def route_collection_params(params) if nested? params[:"#{belongs_to_name}_id"] end end
route_instance_params(instance)
click to toggle source
@return params to pass to instance path
# File lib/active_admin/resource/routes.rb, line 87 def route_instance_params(instance) if nested? [instance.public_send(belongs_to_name).to_param, instance.to_param] else instance.to_param end end
route_name(resource_path_name, options = {})
click to toggle source
# File lib/active_admin/resource/routes.rb, line 72 def route_name(resource_path_name, options = {}) suffix = options[:suffix] || "path" route = [] route << options[:action] # "edit" or "new" route << resource.route_prefix # "admin" route << belongs_to_name if nested? # "category" route << resource_path_name # "posts" or "post" route << suffix # "path" or "index path" route.compact.join('_').to_sym # :admin_category_posts_path end
routes()
click to toggle source
# File lib/active_admin/resource/routes.rb, line 109 def routes Helpers::Routes end