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.


48
49
50
# File 'lib/active_admin/resource/routes.rb', line 48

def initialize(resource)
  @resource = resource
end

Instance Method Details

#batch_action_path(params, additional_params = {}) ⇒ Object


61
62
63
64
65
66
67
68
69
70
71
# File 'lib/active_admin/resource/routes.rb', line 61

def batch_action_path(params, additional_params = {})
  route_name = route_name(
    resource.resources_configuration[:self][:route_collection_name],
    action: :batch_action,
    suffix: (resource.route_uncountable? ? "index_path" : "path")
  )

  query = params.slice(:q, :scope)
  query = query.permit!.to_h
  routes.public_send route_name, *route_collection_params(params), additional_params.merge(query)
end

#collection_path(params, additional_params = {}) ⇒ Object


52
53
54
55
56
57
58
59
# File 'lib/active_admin/resource/routes.rb', line 52

def collection_path(params, additional_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), additional_params
end

#instance_path(instance, additional_params = {}) ⇒ 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


76
77
78
79
80
# File 'lib/active_admin/resource/routes.rb', line 76

def instance_path(instance, additional_params = {})
  route_name = route_name(resource.resources_configuration[:self][:route_instance_name])

  routes.public_send route_name, *route_instance_params(instance), additional_params
end

#member_action_path(action, instance, additional_params = {}) ⇒ String

Returns the path to the member action of this resource.

Examples:

“/admin/posts/1/edit”

Parameters:

  • action (Symbol)
  • instance (ActiveRecord::Base)

    the instance we want the path of

Returns:

  • (String)

    the path to the member action of this resource


86
87
88
89
90
91
# File 'lib/active_admin/resource/routes.rb', line 86

def member_action_path(action, instance, additional_params = {})
  path = resource.resources_configuration[:self][:route_instance_name]
  route_name = route_name(path, action: action)

  routes.public_send route_name, *route_instance_params(instance), additional_params
end