Hi,
On Fri, Oct 10, 2008 at 1:03 PM, Brian Hartin
<[EMAIL PROTECTED]> wrote:
> I know that we shouldn't make database calls in the Initializer, but how
> do we avoid this when a class 'bootstraps' itself when it is required,
> e.g.
>
> class Status < ActiveRecord::Base
> # Add constants representing the various status
> SUBMITTED = self.find(...)
> APPROVED = self.find(...)
> DENIED = self.find(...)
> end
Do these need to be constants? How about:
class Status < ActiveRecord::Base
class << self
def submitted
@submitted ||= find(...)
end
end
end
Or, if they're simple enough, they could just be named scopes:
class Status < ActiveRecord::Base
named_scope :submitted, :conditions => [...]
end
~ j.
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---