Is @request and the other controller attributes not available in a controller''s initialize function? What I''m trying to do: def initialize super server_name = @request.env["SERVER_NAME"] @site=Site.find :first, :conditions => ["server_name=?", server_name] end It gives this error: You have a nil object when you didn''t expect it! The error occured while evaluating nil.env thanks csn __________________________________ Yahoo! Mail - PC Magazine Editors'' Choice 2005 http://mail.yahoo.com
Larry Goats
2005-Nov-10 15:17 UTC
Re: @request et al not available in controller initialize?
You should probably use a before_filter for this... before_filter do |controller| server_name = controller.request.env["SERVER_NAME"] @site = Site.find_by_server_name(server_name) end On 11/9/05, CSN <cool_screen_name90001-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > Is @request and the other controller attributes not > available in a controller''s initialize function? What > I''m trying to do: > > def initialize > super > > server_name = @request.env["SERVER_NAME"] > > @site=Site.find :first, > :conditions => ["server_name=?", server_name] > end > > It gives this error: > > You have a nil object when you didn''t expect it! > The error occured while evaluating nil.env > > > thanks > csn > > > > > __________________________________ > Yahoo! Mail - PC Magazine Editors'' Choice 2005 > http://mail.yahoo.com > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails