I need to load names, from the table ''domains'' into an array (frequently used in my app..) ALL_DOMAINS = Domain.find(:all).map { |d| d.name }.compact I tried to write it in an initialize or in my application.rb BUT problem : when I run a rake db:migrate initially (after creating the database) I get an error.. rake db:migrate --trace (in /Users/yves/Developpement/Projects/rails/presdemoi) ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment rake aborted! Mysql::Error: Table ''yves_pdm_dev.domains'' doesn''t exist: SELECT * FROM `domains` right, the table is not yet created, that''s why I want to do a migrate ... any clue ? thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jeremy Weiskotten
2008-Dec-14 19:15 UTC
Re: need to initialize contant arrays , where to do it...
Kad Kerforn wrote:> I need to load names, from the table ''domains'' into an array > (frequently used in my app..) > ALL_DOMAINS = Domain.find(:all).map { |d| d.name }.compact > > I tried to write it in an initialize or in my application.rb BUT > > problem : when I run a rake db:migrate initially (after creating the > database) > I get an error.. > > rake db:migrate --trace > (in /Users/yves/Developpement/Projects/rails/presdemoi) > ** Invoke db:migrate (first_time) > ** Invoke environment (first_time) > ** Execute environment > rake aborted! > Mysql::Error: Table ''yves_pdm_dev.domains'' doesn''t exist: SELECT * > FROM `domains` > > right, the table is not yet created, that''s why I want to do a > migrate ... > > any clue ? > > thanksI advise against a constant based on database content. You can do something functionally equivalent using a class variable to cache the data the first time it''s requested: class Domain def self.cached_names @@cached_names ||= Domain.find(:all).map { |d| d.name }.compact end end Then use Domain.cached_names instead of your constant. Jeremy http://jeronrails.blogspot.com -- 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 -~----------~----~----~----~------~----~------~--~---
Apparently Analagous Threads
- [LLVMdev] Problem with missing support for non-zero contant initializers.
- [LLVMdev] Problem with missing support for non-zero contant initializers.
- [LLVMdev] Problem with missing support for non-zero contant initializers.
- [LLVMdev] Problem with missing support for non-zero contant initializers.
- [LLVMdev] Problem with missing support for non-zero contant initializers.