Good day. I want to run rb-script via Cron, for inseringt data in database. Is it possible using ActiveRecord, for accessing to DBMS. What should I reguire in rb-file ? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jul-14 09:58 UTC
Re: How to use Rails framework in stand alone ruby file ??? (+)
On 14 Jul 2008, at 09:29, Falko wrote:> > Good day. > > I want to run rb-script via Cron, for inseringt data in > database. > Is it possible using ActiveRecord, for accessing to DBMS. What > should I reguire in rb-file ?There are slightly different answers depending on what you want to do. I''m assuming that you do want to use your app''s models (ie it''s not just activerecord you want, you need to setup the environment The easiest way is to use script/runner, which will setup the environment for you. Failing that, requiring config/boot and config/ environment will load up the rails environment for you. (those aren''t on the load path, so you''ll need something like require File.dirname(__FILE__) + ''/../config/boot'' depending on where your script is in relation to the rest of the app) Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Matthew Rudy Jacobs
2008-Jul-14 11:14 UTC
Re: How to use Rails framework in stand alone ruby file ??? (+)
Falko wrote:> Good day. > > I want to run rb-script via Cron, for inseringt data in > database. > Is it possible using ActiveRecord, for accessing to DBMS. What > should I reguire in rb-file ?I''d suggest you may also want to make this script get run by a rake task /lib/tasks/whatever.rake desc "whatever you want" task :something => :environment do Call::The.code_you_want end then just get cron to call the rake command. -- 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 -~----------~----~----~----~------~----~------~--~---
Fernando Perez
2008-Jul-14 11:48 UTC
Re: How to use Rails framework in stand alone ruby file ??? (+)
Falko wrote:> Good day. > > I want to run rb-script via Cron, for inseringt data in > database. > Is it possible using ActiveRecord, for accessing to DBMS. What > should I reguire in rb-file ?Hi, require ''rubygems'' require ''active_record'' It''s all in the wiki: http://wiki.rubyonrails.org/rails/pages/HowToUseActiveRecordOutsideRails -- 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 -~----------~----~----~----~------~----~------~--~---
Matthew Rudy Jacobs
2008-Jul-14 12:27 UTC
Re: How to use Rails framework in stand alone ruby file ??? (+)
Fernando Perez wrote:> > require ''rubygems'' > require ''active_record'' > > > It''s all in the wiki: > http://wiki.rubyonrails.org/rails/pages/HowToUseActiveRecordOutsideRailsalthough, that will only get you ActiveRecord... it won''t get you the connection setup in your database.yml, or any of the subclasses of ActiveRecord::Base that you''ve set up in your project. Just depends what you''re trying to do. -- 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 -~----------~----~----~----~------~----~------~--~---
chalkers
2008-Jul-14 14:21 UTC
Re: How to use Rails framework in stand alone ruby file ??? (+)
Creating a rake task is the far best solution. You can access all your Models ideal for cron jobs. I use this on one of my projects which updates/add many models every night. On Jul 14, 12:14 pm, Matthew Rudy Jacobs <rails-mailing-l...@andreas- s.net> wrote:> Falko wrote: > > Good day. > > > I want to run rb-script via Cron, for inseringt data in > > database. > > Is it possible using ActiveRecord, for accessing to DBMS. What > > should I reguire in rb-file ? > > I''d suggest you may also want to make this script get run by a rake task > > /lib/tasks/whatever.rake > > desc "whatever you want" > task :something => :environment do > Call::The.code_you_want > end > > then just get cron to call the rake command. > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---