Here’s an e-mail I sent to the Devise mailing list:
Hi,
I patterned my app to this: https://github.com/RailsApps/rails3-subdomains but using AR instead of Mongoid.
I’m trying to extend it such that a user can log in inside a subdomain and at the main area and different classes will handle sessions/registrations in each context.
Here’s my routes:
constraints(Subdomain) do
scope :module => "brand" do
devise_for :subscribers, :class_name => "User", :module => "brand/devise"
match "/dashboard" => "subscribers#dashboard"
match '/' => 'home#index'
end
end
devise_for :subscribers, :class_name => "User"
If I remove the 2nd devise_for, it works in the subdomains but I can’t log in the main domain.
Edit: I partially solved my problem while typing out this mail. Will send it still just in case it helps someone.
Partially, in the sense that I can log in at the subdomain and in the main domain but only Brand::Devise controllers handle both cases.
Changing the routes to this fixed it:
constraints(Subdomain) do
scope :module => "brand" do
match "/dashboard" => "subscribers#dashboard"
match '/' => 'home#index'
end
end
devise_for :subscribers, :class_name => "User", :module => "brand/devise"
Apparently, you can only specify the same resource (:subscribers in this case) only once and the latest call to devise_for will be the one that will apply, regardless if it is within a constraint or not. My motivations in maintaining the resource is to keep my controllers/views dry.
I’m guessing that putting in different resource names will work. It might become confusing though.
2 days of wracking my brains on this and I only had to move a line out of a block. The joys of programming. Haha.
Rystraum