Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm having a peculiar problem with Rails 3 and Devise. I have 3 user types for my Rails App:
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 Sign In's for Owners and Admins are working fine, but i'm unable to get the Clients sign in working.. Here's the error that i get:

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

Application trace is empty.

like image 480
Jasdeep Singh Avatar asked Feb 25 '23 09:02

Jasdeep Singh


1 Answers

According to the Devise docs the after_sign_in_path_for method takes the actual Client object, but you're comparing the input to a set of strings, which will all return false, so your big if clause will return nil. Not sure what Devise is designed to do when that happens, but looking 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 that doesn't help, I would put a debugger statement at the top of the method, to make sure your helpers like 'current_client' are behaving as you expect (and to make sure that after_sign_in_path_for is being called at all).

like image 180
PreciousBodilyFluids Avatar answered Feb 26 '23 21:02

PreciousBodilyFluids