Greg Hauptmann
2009-Sep-05 05:44 UTC
what includes do I need in a Ruby script to have access to Rails methods???
Hi, BACKGROUND: I have a Ruby file I use via cron that makes use of my Ruby on Rails application code (e.g. it uses a model file to create records in the database). When I run this via cron I use "./script/runner filename.rb" and this works fine. QUESTION: I want to be able to run this file by itself (without ./script/runner) so I can debug it in Netbeans (e.g. right-click on the file and go DEBUG). What #includes''s do I need to ensure the file inherits what is required? Note: I did try including the first two lines in the ./script/runner script in my, however this doesn''t seem to work. It just gives a "Run ''/Users/greg/source/bankalerts/lib/alerts/alert.rb -h'' for help." -- Greg http://blog.gregnet.org/
pharrington
2009-Sep-05 05:55 UTC
Re: what includes do I need in a Ruby script to have access to Rails methods???
On Sep 5, 1:44 am, Greg Hauptmann <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > BACKGROUND: I have a Ruby file I use via cron that makes use of my > Ruby on Rails application code (e.g. it uses a model file to create > records in the database). When I run this via cron I use > "./script/runner filename.rb" and this works fine. > > QUESTION: I want to be able to run this file by itself (without > ./script/runner) so I can debug it in Netbeans (e.g. right-click on > the file and go DEBUG). What #includes''s do I need to ensure the file > inherits what is required? > > Note: I did try including the first two lines in the ./script/runner > script in my, however this doesn''t seem to work. It just gives a "Run > ''/Users/greg/source/bankalerts/lib/alerts/alert.rb -h'' for help." > > -- > Greghttp://blog.gregnet.org/To load the whole Rails environment, require File.join(File.dirname(__FILE__), "..", "config", "boot") #adjust the path accordingly for the location of your script require File.join(Rails.root, "config", "environment") If you just need to work with your ActiveRecord models, just require ''active_record'', whatever models you need to work with, and load your database.yml.
Greg Hauptmann
2009-Sep-05 06:22 UTC
Re: what includes do I need in a Ruby script to have access to Rails methods???
2009/9/5 pharrington <xenogenesis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > On Sep 5, 1:44 am, Greg Hauptmann <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> Hi, >> >> BACKGROUND: I have a Ruby file I use via cron that makes use of my >> Ruby on Rails application code (e.g. it uses a model file to create >> records in the database). When I run this via cron I use >> "./script/runner filename.rb" and this works fine. >> >> QUESTION: I want to be able to run this file by itself (without >> ./script/runner) so I can debug it in Netbeans (e.g. right-click on >> the file and go DEBUG). What #includes''s do I need to ensure the file >> inherits what is required? >> >> Note: I did try including the first two lines in the ./script/runner >> script in my, however this doesn''t seem to work. It just gives a "Run >> ''/Users/greg/source/bankalerts/lib/alerts/alert.rb -h'' for help." >> >> -- >> Greghttp://blog.gregnet.org/ > > > To load the whole Rails environment, > > require File.join(File.dirname(__FILE__), "..", "config", "boot") > #adjust the path accordingly for the location of your script > require File.join(Rails.root, "config", "environment") > > > If you just need to work with your ActiveRecord models, just require > ''active_record'', whatever models you need to work with, and load your > database.yml. > > >excellent, thanks pharrington, worked like a charm
Abhinav Saxena
2009-Sep-07 10:43 UTC
Re: what includes do I need in a Ruby script to have access to Rails methods???
You don''t need to include (require) boot.rb as it''s already included in environment.rb. Thanks, Abhinav -- अभिनव http://twitter.com/abhinav On Sat, Sep 5, 2009 at 11:25 AM, pharrington <xenogenesis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Sep 5, 1:44 am, Greg Hauptmann <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > Hi, > > > > BACKGROUND: I have a Ruby file I use via cron that makes use of my > > Ruby on Rails application code (e.g. it uses a model file to create > > records in the database). When I run this via cron I use > > "./script/runner filename.rb" and this works fine. > > > > QUESTION: I want to be able to run this file by itself (without > > ./script/runner) so I can debug it in Netbeans (e.g. right-click on > > the file and go DEBUG). What #includes''s do I need to ensure the file > > inherits what is required? > > > > Note: I did try including the first two lines in the ./script/runner > > script in my, however this doesn''t seem to work. It just gives a "Run > > ''/Users/greg/source/bankalerts/lib/alerts/alert.rb -h'' for help." > > > > -- > > Greghttp://blog.gregnet.org/ > > > To load the whole Rails environment, > > require File.join(File.dirname(__FILE__), "..", "config", "boot") > #adjust the path accordingly for the location of your script > require File.join(Rails.root, "config", "environment") > > > If you just need to work with your ActiveRecord models, just require > ''active_record'', whatever models you need to work with, and load your > database.yml. > > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---