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


#1

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


#2

#!/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
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

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


#3

#!/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
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

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


#4

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


#5

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


#6

Jeroen H. wrote:

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

script/runner ‘require “your_script_here”’


#7

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