开发者

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.


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).


Just a thought, but what would happen if you changed the response to: "/client_accounts/#{current_client.id.to_s}"

What does your rake routes result look like?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜