Forum: Ruby on Rails Adding Subdomain_fu's 'current_subdomain' method to models

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2dddec0f7717cae77ac6bceede6be5bc?d=identicon&s=25 Ram (Guest)
on 2009-05-18 10:10
(Received via mailing list)
Hi,

I have a view in which i have the following collection_select

<%= f.collection_select :category_id, current_account.categories.find
(:all), :id, :name, {:prompt => "-Select-", :include_blank => true} %>

and the current_account method in authentication.rb is

def current_account
    @current_account ||= Account.find_by_subdomain(current_subdomain)
 end

But i get the following error when i try to open the page with that
collection_select in it

undefined local variable or method `current_subdomain' for #<Project:
0x3430e60>

Does this mean i have to make this method available to all my models?
i also tried moving "current_account.categories.find(:all)" to the
controller and storing it in an instance variable and using the
instance variable here instead like

@categories = current_account.categories.find(:all)

<%= f.collection_select :category_id, @categories, :id, :name,
{:prompt => "-Select-", :include_blank => true} %>

That too threw the same error. Any idea whats the ideal way to handle
this?
This topic is locked and can not be replied to.