Reputation: 12339
e.g. I have a model Student:
class Student < ActiveRecord::Base
def self.do_something
ss=Student.find_by_sex "m"
ss.each do |s|
s.blah
s.save
end
end
end
I can do this:
$ rails c
Loading development environment (Rails 3.0.4)
ruby-1.9.2-p180 :001 > Student.do_something
Now, I want a cronjob for this, How do I run above command without (rails c), so I can:
$ ruby student.rb
And get the same result? (I have gems: "mechanize", "hpricot", "to_lang" used in this model)
Thanks!
Upvotes: 1
Views: 166
Reputation: 134
Maybe you should take look at gem whenever. If you don't want to use it, you shoud try to use rails runner:
/great/path/to/my/application/script/rails runner "Student.do_something"
Upvotes: 1