Changing resource_home_path to resource_root_path and add the same redirect to confirmation and password.

This commit is contained in:
Carlos A. da Silva 2009-10-19 00:38:50 -02:00
parent cce3f58e83
commit fc08a7c5ac
6 changed files with 20 additions and 7 deletions

View File

@ -134,6 +134,8 @@ You have also access to the session for this scope:
user_session
After signing in a user, confirming it's account or updating it's password, devise will look for a scoped root path to redirect. Example: For a :user resource, it will use user_root_path if it exists, otherwise default root_path will be used.
Devise let's you setup as many roles as you want, so let's say you already have this User model and also want an Admin model with the same authentication stuff, but not confirmation or password recovery. Just follow the same steps:
# Create a migration with the required fields

View File

@ -24,7 +24,7 @@ class ConfirmationsController < ApplicationController
if resource.errors.empty?
sign_in(resource_name, resource)
set_flash_message :success, :confirmed
redirect_to root_path
redirect_to home_or_root_path
else
render :new
end

View File

@ -30,7 +30,7 @@ class PasswordsController < ApplicationController
if resource.errors.empty?
sign_in(resource_name, resource)
set_flash_message :success, :updated
redirect_to root_path
redirect_to home_or_root_path
else
render :edit
end

View File

@ -32,8 +32,4 @@ class SessionsController < ApplicationController
:scope => [:devise, :sessions], :default => :unauthenticated)
end
def home_or_root_path
home_path = :"#{resource_name}_home_path"
respond_to?(home_path, true) ? send(home_path) : root_path
end
end

View File

@ -42,6 +42,21 @@ module Devise
session[:"#{resource_name}.return_to"] = nil
end
# Checks for the existence of the resource root path. If it exists,
# returns it, otherwise returns the default root_path.
# Used after authenticating a user, confirming it's account or updating
# it's password, so we are able to redirect to scoped root paths.
# Examples (for a user scope):
# map.user_root '/users', :controller => 'users' # creates user_root_path
#
# map.namespace :users do |users|
# users.root # creates user_root_path
# end
def home_or_root_path
home_path = :"#{resource_name}_root_path"
respond_to?(home_path, true) ? send(home_path) : root_path
end
# Attempt to find the mapped route for devise based on request path
def devise_mapping
@devise_mapping ||= Devise.find_mapping_by_path(request.path)

View File

@ -11,7 +11,7 @@ ActionController::Routing::Routes.draw do |map|
map.root :controller => :home
map.connect '/admin_area/password/new', :controller => "passwords", :action => "new"
map.admin_home '/admin_area/home', :controller => "admins", :action => "index"
map.admin_root '/admin_area/home', :controller => "admins", :action => "index"
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'