another noob question... how do I add methods to a class such that they can be access from the console and from rake? Details: I have a ruby script to fetch tweets from the search api. That works fine, saves my tweets to the db. I have a separate, basic rails app to view and manage the tweets and search queries. All of that works fine, too. Now I want to integrate the script into the rails app so it: -runs as a rake task -runs from cron -runs from a refresh button on the tweets page The original ruby script has two methods: search_twitter and get_tweets. I copied those into the Tweet controller, but I cannot access them from the rake file or from the console. If I do Tweet.methods from the console, neither method shows up. So - where is the correct place for these methods, and how do I access them from rake and the console? Thanks! -Luke --~--~---------~--~----~------------~-------~--~----~ 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
2009-Apr-10 07:55 UTC
Re: adding methods, accessing from console and rake tasks
On Apr 10, 4:35 am, LukeG <lgill...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > The original ruby script has two methods: search_twitter and > get_tweets. I copied those into the Tweet controller, but I cannot > access them from the rake file or from the console. If I do > Tweet.methods from the console, neither method shows up. > > So - where is the correct place for these methods, and how do I access > them from rake and the console? >I''d create a model that did these tweet related tasks (or add them to an existing one if appropriate) Fred> Thanks! > > -Luke--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Putting them in the model helped, getting a quick schooling in OOP from someone else helped, too :-) I changed the methods to class methods, and now it behaves as expected. Thanks! On Apr 10, 2:55 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 10, 4:35 am,LukeG<lgill...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > The original ruby script has two methods: search_twitter and > > get_tweets. I copied those into the Tweet controller, but I cannot > > access them from the rake file or from the console. If I do > > Tweet.methods from the console, neither method shows up. > > > So - where is the correct place for these methods, and how do I access > > them from rake and the console? > > I''d create a model that did these tweet related tasks (or add them to > an existing one if appropriate) > > Fred > > > Thanks! > > > -Luke--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---