Class: ActionDispatch::Routing::Mapper
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::Mapper
- Defined in:
- lib/motr/rails/cargo_routing.rb
Instance Attribute Summary collapse
-
#cargo_context_routes_set ⇒ Object
Returns the value of attribute cargo_context_routes_set.
Instance Method Summary collapse
-
#deliver_cargo_for(*models) ⇒ Object
Calling deliver_cargo_for within routes sets up routing for each cargo model.
Instance Attribute Details
#cargo_context_routes_set ⇒ Object
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) = models. models.map!(&:to_sym).each do |mod| sing = ActiveSupport::Inflector.singularize(mod.to_s) plural = ActiveSupport::Inflector.pluralize(mod.to_s) resources *[plural, .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 |