kevintpeng kevintpeng - 5 months ago 7x
Ruby Question

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

gem to insert objects into the database. Is it possible to edit existing records using this gem or using another tool or gem?


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) = "John"!

(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.