On Wednesday, July 20, 2011 5:00:45 PM UTC-6, sreid wrote:
>
> I've just cloned my rails app onto another PC, and I'm having a
> problem getting the database set up.
>
> I've tried rake db:migrate, then db:create and also db:reset, but I
> keep getting an SQLException "no such table". It seems this is due to
> a line in an initializer which accesses one of my tables.
>
> Why do the db:* tasks run the initializers?
I'm guessing because it was easier to implement this way. All task
implementations can be simply assuming that the full rails environment is
available.
> Do I need to move any db
> code out of initalizers
Either that or write said initializers so they can fail gracefully in the
event the database (or tables therein) isn't/aren't setup.
> - if so, where to?
Whatever code path eventually "queries" whatever data/settings/state you
set/configure from your database can use memoization:
def my_settings_from_database
@my_settings_from_database ||= load_my_settings_from_database
end
private
load_my_settings_from_database
# your initializer code
end
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/vbL6wbCuf3UJ.
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.