I have separate models for Devise users and administrators. I also use Basecamp style subdomains. Everything works well, with the exception of a few controllers and actions, when I need to be able to authenticate as a user or administrator.
I currently have authenticate_user! set in my application_controller.rb, and I skip it with skip_before_filter for those controllers and actions that only administrators should have access to.
Unfortunately, I canβt just specify the authentication requirement on each controller, because I still need some controllers and actions for access by both the user and the administrator.
I tried several things to no avail. It seems that if I translate authenticate_user! and authenticate_admin! it is not processed into some subdomain detection logic. Mostly:
current_subdomain = request.subdomains.first if current_subdomain == 'admin' authenticate_admin! else authenticate_user! end
At some point, I was able to try to authenticate, but for some reason it failed, except that the session controller did not need authentication, which led to a redirect cycle (the first for me with Ruby!).
I understand that I can add a field to my user, which indicates the status of the administrator, but the application requires a greater separation of powers between the user and the administrator than it will allow, with the exception of a few controllers and actions.
- Ruby 1.9.2
- Rails 3.0.3
- Develop 1.1.3
source share