Another stupid question: I have a variable that gets inserted into the main layout. Now, it would be silly to go and set it as an instance variable for every single method, right? But when I try to set it in the application.rb file, say using "@variable = Variable.find(:first)", it isn''t available to any of my views. I tried putting the extra "@" in front of the instance variable name to make "@@variable", but that didn''t work either. Anybody know what I''m doing wrong? Should I set it as a constant maybe? Thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Franz Strebel
2007-Oct-12 08:44 UTC
Re: How do you make a variable available to all views?
use the session. session[:myvariable] = .... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 10/12/07, Sean Cahoon <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Another stupid question: > I have a variable that gets inserted into the main layout. Now, it would > be silly to go and set it as an instance variable for every single > method, right? But when I try to set it in the application.rb file, say > using "@variable = Variable.find(:first)", it isn''t available to any of > my views. I tried putting the extra "@" in front of the instance > variable name to make "@@variable", but that didn''t work either. Anybody > know what I''m doing wrong? Should I set it as a constant maybe? > ThanksSet it from a filter in your application controller. Isak> -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bob Showalter
2007-Oct-12 14:31 UTC
Re: How do you make a variable available to all views?
On 10/12/07, Sean Cahoon <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Another stupid question: > I have a variable that gets inserted into the main layout. Now, it would > be silly to go and set it as an instance variable for every single > method, right? But when I try to set it in the application.rb file, say > using "@variable = Variable.find(:first)", it isn''t available to any of > my views. I tried putting the extra "@" in front of the instance > variable name to make "@@variable", but that didn''t work either. Anybody > know what I''m doing wrong? Should I set it as a constant maybe? > ThanksWhy not make a helper in app/helpers/application_rb: def the_var Variable.find :first end Then, in your layout, or in any view: <%= h the_var.some_column %> "global" variables like this are generally a bad idea, and should be avoided if possible. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---