Hi –
On Sat, 16 Dec 2006, Sergio R. wrote:
is it possible to put this declaration somewhere where i can find do:
@site_info.site_name
anywhere in my app?
i have tried putting it in application.rb, and at the top of all my
controllers, with no luck…
I suspect you’ve done something like this:
class ApplicationController < ActionController::Base
@site_info = SiteInfo.find(:first)
and then in another controller:
def do_something
name = @site_info.site_name
end
...
end
and gotten a NoMethodError for calling “site_name” on nil.
Am I close? 
If that’s the case, then the problem is that you’ve defined the
instance variable to be a property of the class object
ApplicationController – which, because of how instance variables work
in Ruby (each one belongs to exactly one object) means that it’s not
available where you really need it to be: namely, the controller
instance.
So, try this:
class ApplicationController < ACB
before_filter set_site_info
def set_site_info
@site_info = SiteInfo.find(:first)
end
...
end
That way, every controller instance will set the variable, and it will
be visible to the controller (and the view, thanks to some “magic”
behind the scenes) for the duration of the request.
David
–
Q. What’s a good holiday present for the serious Rails developer?
A. RUBY FOR RAILS by David A. Black (Ruby for Rails)
aka The Ruby book for Rails developers!
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)