Class: ActionController::Routing::RouteSet::Mapper
- Inherits:
-
Object
- Object
- ActionController::Routing::RouteSet::Mapper
- Defined in:
- lib/devise/rails/routes.rb
Overview
:doc:
Instance Method Summary collapse
-
#devise_for(*resources) ⇒ Object
Includes devise_for method for routes.
Instance Method Details
#devise_for(*resources) ⇒ Object
Includes devise_for method for routes. This method is responsible to generate all needed routes for devise, based on what modules you have defined in your model. Examples: Let’s say you have an User model configured to use authenticatable, confirmable and recoverable modules. After creating this inside your routes:
map.devise_for :users
this method is going to look inside your User model and create the needed routes:
# Session routes for Authenticatable (default)
new_user_session GET /users/sign_in {:controller=>"sessions", :action=>"new"}
user_session POST /users/sign_in {:controller=>"sessions", :action=>"create"}
destroy_user_session GET /users/sign_out {:controller=>"sessions", :action=>"destroy"}
# Password routes for Recoverable, if User model has :recoverable configured
new_user_password GET /users/password/new(.:format) {:controller=>"passwords", :action=>"new"}
edit_user_password GET /users/password/edit(.:format) {:controller=>"passwords", :action=>"edit"}
user_password PUT /users/password(.:format) {:controller=>"passwords", :action=>"update"}
POST /users/password(.:format) {:controller=>"passwords", :action=>"create"}
# Confirmation routes for Confirmable, if User model has :confirmable configured
new_user_confirmation GET /users/confirmation/new(.:format) {:controller=>"confirmations", :action=>"new"}
user_confirmation GET /users/confirmation(.:format) {:controller=>"confirmations", :action=>"show"}
POST /users/confirmation(.:format) {:controller=>"confirmations", :action=>"create"}
You can configure your routes with some options:
* :class_name => setup a different class to be looked up by devise, if it cannot be correctly find by the route name.
map.devise_for :users, :class_name => 'Account'
* :as => allows you to setup path name that will be used, as rails routes does. The following route configuration would setup your route as /accounts instead of /users:
map.devise_for :users, :as => 'accounts'
* :scope => setup the scope name. This is used as the instance variable name in controller, as the name in routes and the scope given to warden. Defaults to the singular of the given name:
map.devise_for :users, :scope => :account
* :path_names => configure different path names to overwrite defaults :sign_in, :sign_out, :password and :confirmation.
map.devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' }
* :path_prefix => the path prefix to be used in all routes.
map.devise_for :users, :path_prefix => "/:locale"
* :sign_out_via => restirct the HTTP method(s) accepted for the :sign_out action (default: :get), possible values are :post, :get, :put, :delete and :any, e.g. if you wish to restrict this to accept only :delete requests you should do:
map.devise_for :users, :sign_out_via => :delete
You need to make sure that your sign_out controls trigger a request with a matching HTTP method.
Any other options will be passed to route definition. If you need conditions for your routes, just map:
map.devise_for :users, :conditions => { :subdomain => /.+/ }
If you are using a dynamic prefix, like :locale above, you need to configure default_url_options through Devise. You can do that in config/initializers/devise.rb or setting a Devise.default_url_options:
Devise.default_url_options do
{ :locale => I18n.locale }
end
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/devise/rails/routes.rb', line 85 def devise_for(*resources) = resources. resources.map!(&:to_sym) resources.each do |resource| mapping = Devise::Mapping.new(resource, .dup) Devise.default_scope ||= mapping.name Devise.mappings[mapping.name] = mapping = mapping..merge(:path_prefix => mapping.raw_path, :name_prefix => "#{mapping.name}_") () do |routes| mapping.for.each do |mod| send(mod, routes, mapping) if self.respond_to?(mod, true) end end end end |