Is there an easy way to have a rails action load up an external file of commands and then execute them?
For example, I'm trying to write a bunch of rails create methods to pre-populate a bunch of tables in a database.
Ideally, I'd like the action to check for the existence of the file, if it exists, run all of the commands, and then delete the file so it doesn't get executed again.
So, the external file would basically look like this:
MyTable.create :name => "New 1"
MyTable.create :name => "New 2"
Is this easy to accomplish in rails?
Some elaboration:
The idea would be that if a certain set up tables need to be touched up after a release, and that you can't do it through a migration script (i.e. you're initializing the database from the schema.rb file), you could:
- Create a file called "update_data.rb" for example
- Place it in an admin directory
- Target some action in the browser (i.e. /admin/update_data)
- Rails would then read in the file, executing the commands line-by-line, and then
- Delete the file when finished so that the actions weren't accidentally executed again
Does that help? It would be a file for one-time actions that need to be executed after a release. If there is a better method, I'm certainly all ears!