Unable to login for user resource - NoMethod error in devise / sessionsController # create

I have a problem with Rails 3 and Devise. I have 3 types of users for my Rails application:
Clients, owners and admins

routes.rb:

devise_for :admins devise_for :owners devise_for :clients 

application_controller.rb:

 def after_sign_in_path_for(resource) if resource == "client" "/client_accounts/" + current_client.id.to_s elsif resource == "admin" stored_location_for(:admins) || "/admin/control_panel" elsif resource == "owner" stored_location_for(:owners) || "/client_accounts" end end 

My login for owners and admins works fine, but I can’t get clients to sign up for work. Here is the error I get:

 NoMethodError in Devise/sessionsController#create undefined method `client_url' for #<Devise::SessionsController:0x10a98f868> 

Application trace is empty.

+4
source share
2 answers

According to Devise docs, the after_sign_in_path_for method accepts the actual Client object, but you are comparing the input with a set of strings that all will return false, so your big if argument will return zero. Not sure if Devise is intended to be executed when this happens, but searching for "client_url" would be a reasonable default.

Try this instead:

 def after_sign_in_path_for(resource) case resource when Client then "/client_accounts/" + current_client.id.to_s when Admin then stored_location_for(:admins) || "/admin/control_panel" when Owner then stored_location_for(:owners) || "/client_accounts" end end 

If this did not help, I would put the debugger operator at the top of the method to make sure your helpers, such as current_client, behave as you expect (and to make sure after_sign_in_path_for is called at all).

+8
source

Just a thought, but what happens if you change the answer to: "/ Client_accounts / # {current_client.id.to_s}"

What do your rake results look like?

0
source

All Articles