We have a few tables that do not change, unless something big happens which will only happen when it is time to deploy. Is there a way to get Rails to cache the contents of these tables? We can''t just go to config files or not DB models for reasons I won''t get into. Thanks, Dave -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060208/5e7f08f4/attachment.html
You could try loading the configuration globaly in the environment.rb file. Then use that throughout your program instead of calling off the model. David On 2/8/06, David Clements <digidigo@gmail.com> wrote:> > We have a few tables that do not change, unless something big happens > which will only happen when it is time to deploy. > > Is there a way to get Rails to cache the contents of these tables? We > can''t just go to config files or not DB models for reasons I won''t get into. > > Thanks, > Dave > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060210/2aeebb2b/attachment.html
David Genord II wrote:> You could try loading the configuration globaly in the environment.rb > file. > Then use that throughout your program instead of calling off the model. > DavidSo, if I have the table configurations like and a Model called Configuration, I could simply load the values from DB on environment.rb like: config = Configuration.find(:first) #I''m only interested in firts row the config model have a column named max_posts_per_page and them use the variable config in every part of my application, like MyController ... def do_some_stuff @posts = Posts.display_posts(config.max_posts_per_page) end will this work as this? -- 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 -~----------~----~----~----~------~----~------~--~---
Hi David, You can do this with class variables. For example, in your Configuration model you can do @@max_posts_per_page = Configuration.find(:first).max_posts_per_page You can add a little function to wrap this if you like, like def self.max_posts_per_page_cached @@max_posts_per_page end Then in MyController you can do def do_some_stuff @posts = Posts.display_posts(Configuration.max_posts_per_page) end J. mp wrote:> David Genord II wrote: >> You could try loading the configuration globaly in the environment.rb >> file. >> Then use that throughout your program instead of calling off the model. >> David > > So, if I have the table configurations like and a Model called > Configuration, I could simply load the values from DB on environment.rb > like: > > config = Configuration.find(:first) #I''m only interested in firts row > > the config model have a column named max_posts_per_page > > and them use the variable config in every part of my application, like > > MyController ... > > def do_some_stuff > @posts = Posts.display_posts(config.max_posts_per_page) > end > > will this work as this?-- 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 -~----------~----~----~----~------~----~------~--~---
Nice, but this is allways hiting my DB, how can I use is witout hitting my DB anytime I request the Configuration.max_posts_per_page? -- 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 -~----------~----~----~----~------~----~------~--~---
I found a soltution that works and don''t touch the DB, only load at application startup In enviroment.rb CONFIG = Configuration.find(:first) #find in the application code: class MyController < ApplicationController def index @ppp = CONFIG.posts_per_page @ppp.freeze #To change any vlue CONFIG.posts_per_page = 22 CONFIG.save end end -- 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 -~----------~----~----~----~------~----~------~--~---