Class: ActionDispatch::Routing::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/motr/rails/cargo_routing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cargo_context_routes_setObject

Returns the value of attribute cargo_context_routes_set.



3
4
5
# File 'lib/motr/rails/cargo_routing.rb', line 3

def cargo_context_routes_set
  @cargo_context_routes_set
end

Instance Method Details

#deliver_cargo_for(*models) ⇒ Object

Calling deliver_cargo_for within routes sets up routing for each cargo model. By default all passed models are routed with:

:controller => 'motr/cargo
:scope_name => 'ModelName'

Override these options when configuring if you would prefer a different controller/scope name



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/motr/rails/cargo_routing.rb', line 12

def deliver_cargo_for(*models)
  
  options = models.extract_options!      
  models.map!(&:to_sym).each do |mod|
    sing   = ActiveSupport::Inflector.singularize(mod.to_s)
    plural = ActiveSupport::Inflector.pluralize(mod.to_s)
    resources *[plural, options.reverse_merge(:controller => 'motr/cargo', :scope_name => "#{sing.classify}")]
  end
  
  unless @cargo_context_routes_set
    scope :controller => 'motr/cargo_contexts' do
      get 'motr/cargo/:scope_name/:scope_id/contexts', :action => :index, :as => :motr_cargo_contexts
      get 'motr/cargo/:scope_name/:scope_id/contexts/:id/edit', :action => :edit, :as => :edit_motr_cargo_context
      put 'motr/cargo/:scope_name/:scope_id/contexts/:id', :action => :update, :as => :motr_cargo_context
      delete 'motr/cargo/:scope_name/:scope_id/contexts/:id', :action => :destroy, :as => :motr_cargo_context
    end
    @cargo_context_routes_set = true
  end
end