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
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
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