Recipe 26 could be used anywhere whereas requiring the environment
requires you to be able to reference a Rails config directory.
As for specifying the environment you could use something like this at
the beginning of your script:
ARGV.each do |pair|
name, value = pair.split(/=/)
ENV[name] = value
end
Then you could invoke your script like:
/myscript RAILS_ENV=production
You could use this to specify other command line options as well:
/myscript RAILS_ENV=production PATH=/some/path FOO=bar
HTH.
V/r
Anthony Eden
On 1/13/07, Dan <danmunk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> Hello,
>
> I need to have some scripts periodically access the same database as my
> Rails application is using and perform some calculations.
>
> >From an earlier post, recipe 26 from Rails Recipes was recommended as a
> way to configure and run the script. I was looking around on on the
> Web and found an article that recommended place my scripts in the
> standard rails ''script'' directory and including the line:
>
> require File.join(File.dirname(__FILE__),
''../config/environment'')
>
> at the beginning of the script. This seems to run fine as well, with
> less repetitive configuration. Aside from the overhead of loading the
> the Rails environment, what would be the advantages and disadvantages
> of each approach?
>
> Also, for the second method what would be the best way to specify the
> environment?
>
> Thanks,
> Dan
>
--
Cell: 808 782-5046
Current Location: Melbourne, FL
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---