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.
Jeroen H. (Guest)
on 2006-02-02 00: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
Warren N. (Guest)
on 2006-02-02 00: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 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)
Warren N. (Guest)
on 2006-02-02 00: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 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)
Alex Y. (Guest)
on 2006-02-02 01:14
(Received via mailing list)
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
Jeroen H. (Guest)
on 2006-02-02 10:52
(Received via mailing list)
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
Alex Y. (Guest)
on 2006-02-02 11:17
(Received via mailing list)
Jeroen H. wrote:
> It doesn't seem to take a file as an argument, just a string..
... Ok...

   script/runner 'require "your_script_here"'
Jeroen H. (Guest)
on 2006-02-02 12:52
(Received via mailing list)
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
This topic is locked and can not be replied to.