Forum: Ruby on Rails adding methods, accessing from console and rake tasks

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9fd7424349068ba5b5062fc314e71ac5?d=identicon&s=25 LukeG (Guest)
on 2009-04-10 05:36
(Received via mailing list)
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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-10 09:56
(Received via mailing list)
On Apr 10, 4:35 am, LukeG <lgill...@gmail.com> 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
9fd7424349068ba5b5062fc314e71ac5?d=identicon&s=25 LukeG (Guest)
on 2009-04-10 23:53
(Received via mailing list)
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...@gmail.com>
This topic is locked and can not be replied to.