Kevin
Kevin

Reputation: 35

How can I edit existing activerecord objects in a sql database using ruby scripts?

How can activerecord objects be edited externally with scripts? I'm currently using the activerecord-import gem to insert objects into the database. Is it possible to edit existing records using this gem or using another tool or gem?

Upvotes: 1

Views: 71

Answers (1)

Matthias Winkelmann
Matthias Winkelmann

Reputation: 16394

That's a bit unspecific. There are quite a few methods. Here's the best:

You can run rails on the console. Try irb in your project's directory, and you're on a REPL that allows you to run code live. Just try something like:

that_guy = User.find(4)
that_guy.name = "John"
that_guy.save!

(Replace User, 4 and name with a model you have, a record's id and some string attribute).

And of course you can also just run a file of ruby against your project: rails runner your_script.rb

And, if I misunderstood you: you can of course access the database through any other means/languages/libraries.

Upvotes: 1

Related Questions