How to create a command line script that acts on a model?

Hi,

I’m looking to create a ruby script that loads a bunch of records and
manipulates these. Where do I start?

I got this to begin with:
#!/usr/bin/env ruby
require File.dirname(FILE) + ‘/…/config/boot’

players = Player.find :all

But it complains about a DB connection. How do I set this up?

Jeroen

#!/usr/bin/env ruby
require File.dirname(FILE) + ‘/…/config/boot’
require File.dirname(FILE) + ‘/…/config/environment’

ActiveRecord::Base.establish_connection
(ActiveRecord::Base.configurations[“development”])

user = User.find(:first)
puts user.to_yaml

Warren

On 01-Feb-06, at 2:34 PM, Jeroen H. wrote:

But it complains about a DB connection. How do I set this up?

Jeroen


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Best Regards,
Warren N…
GNU (http://www.gnu.org.in)

#!/usr/bin/env ruby
require File.dirname(FILE) + ‘/…/config/boot’
require File.dirname(FILE) + ‘/…/config/environment’

ActiveRecord::Base.establish_connection
(ActiveRecord::Base.configurations[“development”])

user = User.find(:first)
puts user.to_yaml

Warren

On 01-Feb-06, at 2:34 PM, Jeroen H. wrote:

But it complains about a DB connection. How do I set this up?

Jeroen


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Best Regards,
Warren N…
GNU (http://www.gnu.org.in)

Jeroen H. wrote:

Hi,

I’m looking to create a ruby script that loads a bunch of records and
manipulates these. Where do I start?

script/runner your_script_here.rb

Alex Y. wrote:

Jeroen H. wrote:

Hi,

I’m looking to create a ruby script that loads a bunch of records and
manipulates these. Where do I start?

script/runner your_script_here.rb

It doesn’t seem to take a file as an argument, just a string…

Jeroen

Jeroen H. wrote:

It doesn’t seem to take a file as an argument, just a string…
… Ok…

script/runner ‘require “your_script_here”’

Alex Y. wrote:

It doesn’t seem to take a file as an argument, just a string…
… Ok…

script/runner ‘require “your_script_here”’

Why didn’t I think of that?? Anyway, thanks for you help, this works
perfectly!

Jeroen