Module: ActionDispatch::Routing::Mapper::Resources

Defined in:
lib/active_scaffold/extensions/routing_mapper.rb

Defined Under Namespace

Classes: ActiveScaffold, ActiveScaffoldAssociation

Instance Method Summary collapse

Instance Method Details

#as_association_routesObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/active_scaffold/extensions/routing_mapper.rb', line 43

def as_association_routes
  resource_scope(:resource, ActiveScaffoldAssociation.new(parent_resource.name, parent_resource.options)) do
    collection do
      ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:collection].each do |name, type|
        match(name, :via => type) if parent_resource.actions.include? name
      end
    end
    member do
      ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:member].each do |name, type|
        match(name, :via => type) if parent_resource.actions.include? name
      end
    end
  end
end

#as_nested_resources(*resources) ⇒ Object



58
59
60
61
62
63
# File 'lib/active_scaffold/extensions/routing_mapper.rb', line 58

def as_nested_resources(*resources)
  options = resources.extract_options!
  resources.each do |resource|
    resources(resource, options.merge(:parent_scaffold => merge_module_scope(@scope[:module], parent_resource.plural), :association => resource)) { yield if block_given? }
  end
end

#as_routes(opts = {:association => true}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/active_scaffold/extensions/routing_mapper.rb', line 25

def as_routes(opts = {:association => true})
  resource = parent_resource
  resource_scope(:resource, ActiveScaffold.new(parent_resource.name, parent_resource.options)) do
    collection do
      ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection].each do |name, type|
        match(name, :via => type) if parent_resource.actions.include? name
      end
    end
    member do
      ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:member].each do |name, type|
        match(name, :via => type) if parent_resource.actions.include? name
      end
      get 'list', :action => :index if resource.actions.include? :index
    end
  end
  as_association_routes if opts[:association]
end

#as_scoped_routes(*scopes) ⇒ Object



65
66
67
68
69
70
# File 'lib/active_scaffold/extensions/routing_mapper.rb', line 65

def as_scoped_routes(*scopes)
  options = scopes.extract_options!
  scopes.each do |scope|
    resources(scope, options.merge(:parent_scaffold => merge_module_scope(@scope[:module], parent_resource.plural), :named_scope => scope, :controller => parent_resource.plural)) { yield if block_given? }
  end
end