hello, I have an array that I want accessible to all controllers/views that looks like this: @admintypes = [''locations'',''clusters'',''computers''] ; I tried setting this in application_controller.rb , but it doesnt becom available. I also would prefer to not have to call a method everytime i needed it since its used in a large number of views and layouts. thanks adam
Hello Adam, Adam Denenberg said the following on 2005-08-25 10:22:> I have an array that I want accessible to all controllers/views that > looks like this:What you need is to really define a constant, like this: AdminTypes = %w(locations clusters computers).freeze Then, in your views and controllers, you can refer to this top-level constant as AdminTypes. The way you were doing it was defining an instance variable in the top level execution context, which is an object, but is not the same object as when your controller is executing. Hope that helps ! François
does this go in application_controller.rb ? and is it still accessed as <% for a in @AdminTypes %> inside the view ? thanks adam On Aug 25, 2005, at 10:46 AM, François Beausoleil wrote:> Hello Adam, > > Adam Denenberg said the following on 2005-08-25 10:22: > >> I have an array that I want accessible to all controllers/views >> that looks like this: >> > > What you need is to really define a constant, like this: > AdminTypes = %w(locations clusters computers).freeze > > Then, in your views and controllers, you can refer to this top- > level constant as AdminTypes. > > The way you were doing it was defining an instance variable in the > top level execution context, which is an object, but is not the > same object as when your controller is executing. > > Hope that helps ! > François > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >
i seemed to have figured this out by using a Global variable. I did $AdminTypes = %w(locations computers clusters).freeze in application_controller.rb and now it seems to be available. I hope this is the correct way to do this. adam On Aug 25, 2005, at 11:42 AM, Adam Denenberg wrote:> does this go in application_controller.rb ? > > and is it still accessed as > > <% for a in @AdminTypes %> > > inside the view ? > > thanks > adam > > On Aug 25, 2005, at 10:46 AM, François Beausoleil wrote: > > >> Hello Adam, >> >> Adam Denenberg said the following on 2005-08-25 10:22: >> >> >>> I have an array that I want accessible to all controllers/views >>> that looks like this: >>> >>> >> >> What you need is to really define a constant, like this: >> AdminTypes = %w(locations clusters computers).freeze >> >> Then, in your views and controllers, you can refer to this top- >> level constant as AdminTypes. >> >> The way you were doing it was defining an instance variable in the >> top level execution context, which is an object, but is not the >> same object as when your controller is executing. >> >> Hope that helps ! >> François >> >> _______________________________________________ >> 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 > >