Thanks, this sounds like what I need.
On Feb 22, 7:24 pm, Jeff Lewis jeff.bu...@gmail.com wrote:
To initialize some db-read var (tidbit in your example) that would
survive and be callable for each subsequent app request, you'll want
to do so via lazy-initialization using a before_filter
hi,
Ruby pocket reference looks useful, think I'll order a copy.
Regarding the class method, just wondering when/how this method should
get called.
Tonypm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby
on
Hi Eric,
On Sat, 2009-02-21 at 12:45 -0800, ericindc wrote:
Title pretty much explains it. I'd like to set a variable the stores
a single Model object inside of application.rb since it will be used
on every single page. I've tried both class and instance variables,
but to no avail. The
To initialize some db-read var (tidbit in your example) that would
survive and be callable for each subsequent app request, you'll want
to do so via lazy-initialization using a before_filter (mentioned by
bill) in application.rb.
How you store such lazy-init vars between requests depends on the
For actual read-only data that is an instance of a model class, I'd
set up a class method instead. So for a default location, in
Location.rb,
def self.default_location
@@default_location ||= Location.find_by_name(San Francisco)
end
This fixes your migration problem, doesn't reload it with
So why not use that, then? Whatever works...
Also, you might brush up on MVC and beginner's Ruby as far as setting
variables in models go:
http://wiki.rubyonrails.org/rails/pages/UnderstandingRailsMVC
On Feb 21, 12:45 pm, ericindc ericmilf...@gmail.com wrote:
Title pretty much explains it.
I don't generally follow the whatever works... approach because
there is usually a best practice. That said, I want to avoid the
global variable because having $tidbit = Tidbit.random declared in my
application.rb broke my migrations. Running migrations from version 0
when the Tidbits database
7 matches
Mail list logo