Sha256: 6dd05b898dd002a31313f2a411835c48625cbf77d7e75bfddc4b37eb557d2284

Contents?: true

Size: 2 KB

Versions: 5

Compression:

Stored size: 2 KB

Contents

module ActionDispatch
  module Routing
    ACTIVE_SCAFFOLD_CORE_ROUTING = {
        :collection => {:show_search => :get, :render_field => :get},
        :member => {:row => :get, :update_column => :post, :render_field => :get}
    }
    ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING = {
        :collection => {:edit_associated => :get, :new_existing => :get, :add_existing => :post},
        :member => {:edit_associated => :get, :add_association => :get, :destroy_existing => :delete}
    }
    class Mapper
      module Base
        def as_routes(options = {:association => true})
          collection do
            ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection].each {|name, type| send(type, name)}
          end
          member do
            ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:member].each {|name, type| send(type, name)}
          end
          as_association_routes if options[:association]
        end
        
        def as_association_routes
          collection do 
            ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:collection].each {|name, type| send(type, name)}
          end
          member do
            ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:member].each {|name, type| send(type, name)}
          end
        end
        
        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
        
        def as_scoped_routes(*scopes)
          options = scopes.extract_options!
          scopes.each do |scope|
            resources(parent_resource.plural, options.merge(:parent_scaffold => merge_module_scope(@scope[:module], parent_resource.plural), :named_scope => scope, :as => :scope)) { yield if block_given? }
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
active_scaffold-3.1.20 lib/active_scaffold/extensions/routing_mapper.rb~
active_scaffold-3.1.19 lib/active_scaffold/extensions/routing_mapper.rb~
active_scaffold-3.1.18 lib/active_scaffold/extensions/routing_mapper.rb~
active_scaffold-3.1.17 lib/active_scaffold/extensions/routing_mapper.rb~
active_scaffold-3.1.15 lib/active_scaffold/extensions/routing_mapper.rb~