Adam Dorsey
2008-Jul-15 01:09 UTC
Accessing controller specific variables application-wide
Not sure if I described this the best in the subject, but here is my problem... I have a ''settings'' table, that I am storing application configuration data. On my settings "edit" page, I am just grabbing the first entry (you can''t add more entries, again, just a config table) [code] @setting = Setting.find(1) [/code] I need to access some of that data in the main layout. For instance, the color (hex) of the template. The "name" of the application, etc. How would I go about doing that? -- 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Müller
2008-Jul-15 08:48 UTC
Re: Accessing controller specific variables application-wide
Many ways to do this. Either declare a before_filter in application.rb and load the settings every time before_filter :load_settings def load_settings @setting = Setting.find(1) end Or, if you don''t need it that often, you can define a method def get_settings @setting ||= Setting.find(1) end This will load the setting the first time it''s called. If it was called before, it just returns the @setting --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---