1

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

You have all the ActiveRecord finder methods at your disposal so find_by(name: 'Bob') also works. rails runner or a rake task is a good plan for these utility scripts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.