Sy Ys wrote:
I have a script which scrapes a website. Since it takes nearly an hour
to complete, making it part of the controller doesn’t make sense because
it would simply time out.
However, this script needs access to my models (it adds to my database).
How can I do this? I am sure there is something simple I am missing.
It depends exactly how it’s working.
Often I end up defining a module and sticking it in /lib,
but, equally, any associated model code should live in the model.
Then, in order to run it,
either create a /bin directory
or stick it in /script
inside your script, make sure you require “environment.rb” like this
require File.expand_path(File.dirname(FILE) +
then when you run your script (on cron or whatever), it’ll first load up
the rails stack, giving you access to the db, models, and all that.