Rails 3, Devise and single table inheritance issue
I reproduced the issue I'm getting in a simple rails project available at githu开发者_运维技巧b :
Running rails 3.1rc4: https://github.com/demental/devise_sti
Running rails 3.0.9: https://github.com/demental/devise_sti_rails3
Basically :
- I have a User model, that uses devise behaviour
- I have Admin model that inherits from User
- I have two devise resources in my routing.
When signing in as an Admin, I get rejected by the authenticate_admin! filter, just like if I was a User.
I don't know if it's an issue or if I did something wrong... any idea ?
Answering to myself:
I have two ways to avoid this issue, that occured only when running tests:
- As the Devise mappings are iterated from first to last devise_for declared in the routes, I can check the order of these lines, and put the devise_for :user last. The check is done with is_a so as admin.is_a(User), Admin was matched as user. Inversing the devise_for orders made the Admin match before User.
- I can also (cleaner I guess) use the scope parameter in the sign_in helper method : sign_in :admin Factory(:admin)
精彩评论