Archive for February, 2012
How to get out of debt by Dave Ramsey
I’m keeping this here as a reminder to myself:
- $1000 Emergency Fund
- Debt snowball: Start from the small ones
- 3 to 6 months of expenses in savings
- Invest 15% of income
- *College fund
- *Mortgage fund
- Share
* doesn’t really apply to me yet
You can find out more from his website:
2 days 1 line: devise_for in different constraints
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