plataformatec/devise — Issue #1649: customize session create method getting routing error
Author: urjitrajgor
Created: 2012-02-15 13:47:59+00:00
State: open

I am using devise and i have user table with admin field where admin value is tru if he login as admin.

i am login from home page by rendring new.html file from session view.

I customize session controller in user controller
I really like to authenticate my devise user through 2 different interfaces with a view to have 2 different layout.
For example I would be able to use /users/sign_in and /admin/sign_in based on the same User model.
please hemp me.
routes.rb
*************
devise_for :users, :controllers => {:sessions => 'devise/sessions', :registrations => 'devise/registrations'} do

get "/login", :to => "devise/sessions#new", :as => :login
get "/signup", :to => "devise/registrations#new", :as => :signup
get "/logout", :to => "devise/sessions#destroy", :as => :logout

match "users/create/:resource_name", :to => "users#create", :as => :session
match "/admin/index/:resource_name", :to => 'admin#index', :as => :admin
match "/home/index/:resource_name", :to => 'home#index', :as => :user
end
root :to => "home#index"

resources :items
resources :regions
resources :categories
resources :items

User controller
******************
class UsersController < Devise::SessionsController
prepend_before_filter :allow_params_authentication!, :only => :create
def view
@users = User.all
end

def create
resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_in_path_for(resource)
end

def after_sign_in_path_for(resource)
if current_user.admin?
stored_location_for(resource) || admin_path
else
stored_location_for(resource) || user_path
end
end

protected

def auth_options
{ :scope => resource_name, :recall => "#{controller_path}#new" }
end

end

new.html.erb
*******************

<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>

<%= f.label :email %>

<%= f.email_field :email, :size => "20" %>

<%= f.label :password %>

<%= f.password_field :password, :size => "20"%>

<% if devise_mapping.rememberable? -%>

<%= f.check_box :remember_me %> <%= f.label :remember_me %>

<% end -%>

<%= f.submit "Sign in" %>

<% end %>

error i am getting
**************************

rocessing by UsersController#create as HTML
Parameters: {"commit"=>"Sign in", "authenticity_token"=>"ax/xb5znIAvyVBMGCQa0i/rQWLXNKV0eKaf10ClF/Lo=", "utf8"=>"\342\234\223", "resource_name"=>"user", "user"=>{"remember_me"=>"0", "password"=>"[FILTERED]", "email"=>"urjit.rajgor@radixweb.com"}}
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'urjit.rajgor@radixweb.com' LIMIT 1
Redirected to http://localhost:3000/index
Completed 302 Found in 184ms (ActiveRecord: 0.0ms)

Started GET "/index" for 127.0.0.1 at Wed Feb 15 19:03:32 +0530 2012

ActionController::RoutingError (No route matches [GET] "/index"):
actionpack (3.2.0.rc2) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.0.rc2) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.0.rc2) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.0.rc2) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.0.rc2) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.0) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.0) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.0.rc2) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.0) lib/rack/lock.rb:15:in `call'
actionpack (3.2.0.rc2) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.2.0.rc2) lib/rails/engine.rb:479:in `call'
rack (1.4.0) lib/rack/content_length.rb:14:in `call'
railties (3.2.0.rc2) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.0) lib/rack/handler/webrick.rb:59:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
rack (1.4.0) lib/rack/handler/webrick.rb:13:in `run'
rack (1.4.0) lib/rack/server.rb:265:in `start'
railties (3.2.0.rc2) lib/rails/commands/server.rb:70:in `start'
railties (3.2.0.rc2) lib/rails/commands.rb:55
railties (3.2.0.rc2) lib/rails/commands.rb:50:in `tap'
railties (3.2.0.rc2) lib/rails/commands.rb:50
script/rails:6:in `require'
script/rails:6

Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.2.0.rc2/lib/action_dispatch/middleware/templates/rescues/routing_error.er