Class: ActionController::Routing::RouteSet::Mapper
- Includes:
- ActionController::Resources
- Defined in:
- lib/action_controller/routing/route_set.rb
Overview
Mapper instances are used to build routes. The object passed to the draw block in config/routes.rb is a Mapper instance.
Mapper instances have relatively few instance methods, in order to avoid clashes with named routes.
Constant Summary
Constants included from ActionController::Resources
ActionController::Resources::INHERITABLE_OPTIONS
Instance Method Summary collapse
-
#connect(path, options = {}) ⇒ Object
Create an unnamed route with the provided
path
andoptions
. -
#initialize(set) ⇒ Mapper
constructor
:nodoc:.
-
#method_missing(route_name, *args, &proc) ⇒ Object
:nodoc:.
-
#named_route(name, path, options = {}) ⇒ Object
:nodoc:.
-
#namespace(name, options = {}, &block) ⇒ Object
Enables the use of resources in a module by setting the name_prefix, path_prefix, and namespace for the model.
-
#root(options = {}) ⇒ Object
Creates a named route called “root” for matching the root level request.
Methods included from ActionController::Resources
Constructor Details
#initialize(set) ⇒ Mapper
:nodoc:
12 13 14 |
# File 'lib/action_controller/routing/route_set.rb', line 12 def initialize(set) #:nodoc: @set = set end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(route_name, *args, &proc) ⇒ Object
:nodoc:
55 56 57 58 |
# File 'lib/action_controller/routing/route_set.rb', line 55 def method_missing(route_name, *args, &proc) #:nodoc: super unless args.length >= 1 && proc.nil? @set.add_named_route(route_name, *args) end |
Instance Method Details
#connect(path, options = {}) ⇒ Object
Create an unnamed route with the provided path
and options
. See ActionController::Routing for an introduction to routes.
18 19 20 |
# File 'lib/action_controller/routing/route_set.rb', line 18 def connect(path, = {}) @set.add_route(path, ) end |
#named_route(name, path, options = {}) ⇒ Object
:nodoc:
32 33 34 |
# File 'lib/action_controller/routing/route_set.rb', line 32 def named_route(name, path, = {}) #:nodoc: @set.add_named_route(name, path, ) end |
#namespace(name, options = {}, &block) ⇒ Object
Enables the use of resources in a module by setting the name_prefix, path_prefix, and namespace for the model. Example:
map.namespace(:admin) do |admin|
admin.resources :products,
:has_many => [ :tags, :images, :variants ]
end
This will create admin_products_url
pointing to “admin/products”, which will look for an Admin::ProductsController. It’ll also create admin_product_tags_url
pointing to “admin/products/#product_id/tags”, which will look for Admin::TagsController.
47 48 49 50 51 52 53 |
# File 'lib/action_controller/routing/route_set.rb', line 47 def namespace(name, = {}, &block) if [:namespace] ({:path_prefix => "#{.delete(:path_prefix)}/#{name}", :name_prefix => "#{.delete(:name_prefix)}#{name}_", :namespace => "#{.delete(:namespace)}#{name}/" }.merge(), &block) else ({:path_prefix => name, :name_prefix => "#{name}_", :namespace => "#{name}/" }.merge(), &block) end end |
#root(options = {}) ⇒ Object
Creates a named route called “root” for matching the root level request.
23 24 25 26 27 28 29 30 |
# File 'lib/action_controller/routing/route_set.rb', line 23 def root( = {}) if .is_a?(Symbol) if source_route = @set.named_routes.routes[] = source_route.defaults.merge({ :conditions => source_route.conditions }) end end named_route("root", '', ) end |