Class: ActiveAdmin::Resource::Routes::RouteBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/active_admin/resource/routes.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ RouteBuilder

Returns a new instance of RouteBuilder.


36
37
38
# File 'lib/active_admin/resource/routes.rb', line 36

def initialize(resource)
  @resource = resource
end

Instance Method Details

#collection_path(params) ⇒ Object


40
41
42
43
44
45
46
47
# 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) ⇒ String

Returns the path to the edit page of this resource.

Examples:

“/admin/posts/1/edit”

Parameters:

  • instance (ActiveRecord::Base)

    the instance we want the path of

Returns:

  • (String)

    the path to the edit page of this resource


61
62
63
64
65
66
# 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) ⇒ String

Returns the path to this resource collection page.

Examples:

“/admin/posts/1”

Parameters:

  • instance (ActiveRecord::Base)

    the instance we want the path of

Returns:

  • (String)

    the path to this resource collection page


52
53
54
55
56
# 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