开发者

Rails 3, Devise and single table inheritance issue

开发者 https://www.devze.com 2023-03-18 18:41 出处:网络
I reproduced the issue I\'m getting in a simple rails project available at githu开发者_运维技巧b :

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:

  1. 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.
  2. I can also (cleaner I guess) use the scope parameter in the sign_in helper method : sign_in :admin Factory(:admin)
0

精彩评论

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