I am trying to insert data into a SQLite database that is used for a Rails application.
I initially thought I could have used SQLite manager and insert into tablename (value) values ('value') however, it did not insert anything into the table and did not produce an error.
Am I doing anything wrong? Is there a way to do this directly with Rails?
I thought I could use some sort of activerecord migration and just rake db:migrate, however I have been unable to find the appropriate commands.
rails runneris a nice way to leverage the Rails runtime, without needing to load the entire Rails stack for your application. It’ll give you the full ActiveRecord resources for your underlying DB, making it easy to do database operations.From the
runnerbuilt-in help:rails runner Usage: runner [options] ('Some.ruby(code)' or a filename) -e, --environment=name Specifies the environment for the runner to operate under (test/development/production). Default: development -h, --help Show this help message. You can also use runner as a shebang line for your scripts like this: ------------------------------------------------------------- #!/usr/bin/env /Users/greg/junk/foo/script/rails runner Product.all.each { |p| p.price *= 2 ; p.save! }I’ve used this several times for jobs that loaded data underneath Rails into the database. It’d be a great solution for what you need to do.
“Rails task: script/runner or rake?” is worth reading too for more information.