I have created a site which utilizes subdomains and searches whether or not the user is at: subdomain.domain.com
or domain.com
. If the user is in subdomain.domain.com, /views/layouts/application.html.erb
appears, if the user is in domain.com /views/layouts/promo_site.html.erb
appears. To accomplish this I closely followed Robby on Rails directions.
Both layouts utilize the same controller.
I've isolated the following problem:
- Controller logic is causing fail. "undefined method `orders' for nil:NilClass"
- If the controller is in the correct scope,
subdomain.url.com
the current_account method works fine. If it is in theurl.com
scope, the current_account method produces a nil. A full explanation of the current_account method is here. - How do I use the controller under these conditions?
Example of utilization of the current_account method:
created_purchase_orders = current_account.orders.find(:all, :conditions => ["created_at >= ?", 3.days.ago], :order => "created_at DESC")
*the above code produces a nil under the url.com condition, and works fine in subdomain.url.com
Would something like [current_account.orders.find(:all, :conditions => ["created_at >= ?", 3.days.ago], :order => "created_at DESC")] unless current_account.nil?
be a suggested fix?