I don''t know if there''s a more Rails or Ruby way to do this,
but the
best I''ve done is write a ruby script that bootstraps Rails, get my
work done through ActiveRecord (so I don''t by pass any of my business
logic), and then tell cron to run this script every so often.
The following code works for me in bootstrapping Rails:
#!/usr/bin/env ruby
# Ensure the environment was specified
if ARGV.length != 1
puts "usage: ruby dummy_records.rb <rails_env>"
exit 1
end
$LOAD_PATH << File.expand_path(File.dirname(__FILE__))
ENV[''RAILS_ENV''] = ARGV.first ||
ENV[''RAILS_ENV'']
require ''rubygems''
require File.dirname(__FILE__) + ''/../config/boot''
require "#{RAILS_ROOT}/config/environment"
def connect(environment)
conf = YAML::load(File.open(File.dirname(__FILE__) + ''/../config/
database.yml''))
ActiveRecord::Base.establish_connection(conf[environment])
end
# Open ActiveRecord connection
connect(ARGV.first)
# Enter code here to interact with your models.
Warm regards,
David Richards
On May 23, 10:55 pm, Sonny Crimson
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Hello, i have a question about a problem i can''t figure out how to
> solve.
>
> I have a standard RoR application made with the classic MVC model, and I
> need to (for example) edit a value in a table with a time-based rule.
>
> EX:
>
> starting table:
>
> user | money
> ----------------
> |
> john | 500
>
> after 1 minute:
>
> user | money
> ----------------
> |
> john | 510
>
> etc..
>
> How to do that?
> Really thank you.
>
> --
> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---