Hi, This should be easy, for some reason I can''t remember how to do it. I have in /lib a file called "joe_converter.rb" that I want to be able to run from terminal. Here''s the beginning of "joe_converter.rb": ********************************************** require ''active_record'' # Takes in a URL, creates all needed objects, and ends up creating an LqSnapshot for that URL class JoeConverter def self.do_the_conversion url, scores, user_id ********************************************** How can I run this from terminal correctly? I tried with "script/runner", and put in the necessary parameters, but I get back this: wrong number of arguments (0 for 5) (ArgumentError) Anyone have any ideas about this? -- 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 -~----------~----~----~----~------~----~------~--~---
Harold
2009-Jan-09 20:57 UTC
Re: How to pass parameters to a script in "lib" from terminal
I don''t think you can do it using script/runner (I may be wrong). You could run the script directly using ruby lib/joe_converter.rb, and handle the parameters in your script. Your rails app wouldn''t load in this case. Another (probably preferred) option is to create a rake task in lib/tasks that takes the parameters and calls JoeConverter.do_the_conversion passing the parameters. If you are accessing any other classes/modules of your rails app (like any model for instance), go with the rake task as they would load as well. Someone else might have better ideas though ;) On Jan 9, 3:49 pm, Joe Peck <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > > This should be easy, for some reason I can''t remember how to do it. > > I have in /lib a file called "joe_converter.rb" that I want to be able > to run from terminal. Here''s the beginning of "joe_converter.rb": > ********************************************** > require ''active_record'' > > # Takes in a URL, creates all needed objects, and ends up creating an > LqSnapshot for that URL > class JoeConverter > def self.do_the_conversion url, scores, user_id > ********************************************** > > How can I run this from terminal correctly? I tried with > "script/runner", and put in the necessary parameters, but I get back > this: > > wrong number of arguments (0 for 5) (ArgumentError) > > Anyone have any ideas about this? > -- > 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 -~----------~----~----~----~------~----~------~--~---
Joe Peck
2009-Jan-09 21:21 UTC
Re: How to pass parameters to a script in "lib" from termina
I''ve put it in a raketask, works now, except for one thing; if I try to pass a hash to it as a parameter, it seems like it just stops. Hmm... -- 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 -~----------~----~----~----~------~----~------~--~---
Harold A. Giménez Ch.
2009-Jan-09 21:32 UTC
Re: How to pass parameters to a script in "lib" from termina
Well, you have to play nice with the "rules" of the command line (like no spaces etc). Also note that whatever comes into your rake task is simply a string. You would have to parse that string and build any object you need, such as a hash or array... Any code on how you''re handling the params? On Fri, Jan 9, 2009 at 4:21 PM, Joe Peck <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > I''ve put it in a raketask, works now, except for one thing; if I try to > pass a hash to it as a parameter, it seems like it just stops. Hmm... > -- > 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 -~----------~----~----~----~------~----~------~--~---