Forum: Ruby on Rails how to create a command line script that acts on a model?

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.
B9a732fc30c32098347a0177c75ee27b?d=identicon&s=25 Jeroen Houben (Guest)
on 2006-02-01 23:37
(Received via mailing list)
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
Bb482bc8f30152b005087fff1d392266?d=identicon&s=25 Warren Noronha (Guest)
on 2006-02-01 23:58
(Received via mailing list)
#!/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 Houben wrote:

>
> But it complains about a DB connection. How do I set this up?
>
>
> Jeroen
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails

Best Regards,
Warren Noronha.
GNU (http://www.gnu.org.in)
711eb56e970b483e2c9d929bd036a89e?d=identicon&s=25 Warren Noronha (Guest)
on 2006-02-01 23:58
(Received via mailing list)
#!/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 Houben wrote:

>
> But it complains about a DB connection. How do I set this up?
>
>
> Jeroen
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails

Best Regards,
Warren Noronha.
GNU (http://www.gnu.org.in)
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-02-02 00:14
(Received via mailing list)
Jeroen Houben 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
B9a732fc30c32098347a0177c75ee27b?d=identicon&s=25 Jeroen Houben (Guest)
on 2006-02-02 09:52
(Received via mailing list)
Alex Young wrote:
> Jeroen Houben 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
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-02-02 10:17
(Received via mailing list)
Jeroen Houben wrote:
> It doesn't seem to take a file as an argument, just a string..
... Ok...

   script/runner 'require "your_script_here"'
B9a732fc30c32098347a0177c75ee27b?d=identicon&s=25 Jeroen Houben (Guest)
on 2006-02-02 11:52
(Received via mailing list)
Alex Young 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
This topic is locked and can not be replied to.