Hi folks, Just after a ''best-practise'' pointer with this one really; I have a ''setup'' model for my application which only has a single record, holding the current settings of the app e.g. its mode (maintenance, normal, readonly) etc I need to check the app''s settings, at least once per page-load, sometimes more. I know I could do this easily by pulling the record each time but was wondering if using global variables or something like a helper would be better? I do need to make these calls in both the controllers and views however. Thanks in advance, Paul -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi folks, Just after a ''best-practise'' pointer with this one really; I have a ''setup'' model for my application which only has a single record, holding the current settings of the app e.g. its mode (maintenance, normal, readonly) etc I need to check the app''s settings, at least once per page-load, sometimes more. I know I could do this easily by pulling the record each time but was wondering if using global variables or something like a helper would be better? I do need to make these calls in both the controllers and views however. Thanks in advance, Paul -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi folks, Just after a ''best-practise'' pointer with this one really; I have a ''setup'' model for my application which only has a single record, holding the current settings of the app e.g. its mode (maintenance, normal, readonly) etc I need to check the app''s settings, at least once per page-load, sometimes more. I know I could do this easily by pulling the record each time but was wondering if using global variables or something like a helper would be better? I do need to make these calls in both the controllers and views however. Thanks in advance, Paul -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 20 September 2011 12:36, paulo <paul.a.taylor84-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi folks,Hello, Just the one post would suffice ;-)> I know I could do this easily by pulling the record each time but was > wondering if using global variables or something like a helper would > be better? I do need to make these calls in both the controllers and > views however.Have a look at something like SettingsLogic - which stores site-settings as a YAML file, and is globally accessible as a singleton model. If you *need* to store the settings in the DB (for easy access to change them for instance), then there are some alternative gems that offer this sort of "global site settings" functionality (or you could just change SettingsLogic to serialise to a model... Have a look on http://ruby-toolbox.com/ as one source for comparisons. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I use a DB table but store one value per setting. Then in my code I just access whichever record I need to gain access to the value. This gives me great flexibility to maintain the setting values. Then I access the table only when needed. It might not be as fast as having all values retrieved at once but in my case it does not make any real difference in the performance of the application. On Sep 20, 7:29 am, paulo <paul.a.taylo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi folks, > > Just after a ''best-practise'' pointer with this one really; > > I have a ''setup'' model for my application which only has a single > record, holding the current settings of the app e.g. its mode > (maintenance, normal, readonly) etc > > I need to check the app''s settings, at least once per page-load, > sometimes more. > > I know I could do this easily by pulling the record each time but was > wondering if using global variables or something like a helper would > be better? I do need to make these calls in both the controllers and > views however. > > Thanks in advance, > > Paul-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.