This is probably simple to most of the experts here, but what is the best way to set variables to be used by a layout? Obviously, it shouldn''t be in each routine in the controller as that would have to be duplicated in every module - very error prone. Assuming you need to set something based on the day of the month where would you put the code so that the controller''s layout could use it. Thanks in advance ---Michael -- 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 -~----------~----~----~----~------~----~------~--~---
Probably in a before_filter. If you really want the data available everywhere, put the before_filter in application.rb. If only for a given controller, then implement it for that class only. On Jun 7, 2007, at 5:12 PM, Michael Satterwhite wrote:> > This is probably simple to most of the experts here, but what is the > best way to set variables to be used by a layout? Obviously, it > shouldn''t be in each routine in the controller as that would have > to be > duplicated in every module - very error prone. Assuming you need to > set > something based on the day of the month where would you put the > code so > that the controller''s layout could use it. > > Thanks in advance > ---Michael > > -- > Posted via http://www.ruby-forum.com/. > > >Steve Ross sross-ju+vs0qJmyeQKKlA4PA9hA@public.gmane.org http://www.calicowebdev.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 -~----------~----~----~----~------~----~------~--~---
On 6/7/07, Michael Satterwhite <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > This is probably simple to most of the experts here, but what is the > best way to set variables to be used by a layout? Obviously, it > shouldn''t be in each routine in the controller as that would have to be > duplicated in every module - very error prone. Assuming you need to set > something based on the day of the month where would you put the code so > that the controller''s layout could use it. > > Thanks in advance > ---MichaelI think the answer partially depends on what data you are trying to display. If the data is static, or related to something predictable, like the date, I would create a helper function and create the data in there. There might be cases where the data you want needs to come from the database though, and for that I would create a before filter: before_filter :do_stuff def do_stuff #stuff! end You should read up on before filters, there are more options that make them conditional and such that can come in handy. Read more here http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html -- F. Morgan Whitney http://www.blizzo.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 -~----------~----~----~----~------~----~------~--~---