I can run the following commands in the console for my Rails application and import the CSV file into my database.
require 'csv'
CSV.open('myfile.csv', 'r') do |row|
Trunk.create!(:npa => row[0], :nxxFrom => row[1], :nxxTo => row[2], :trnk => row[3])
end
However, I would like to facilitate the process by simply creating a script for it. The problem is that I donβt know how to write an application specific script. To run the above commands, I need to start the console in the application folder as follows:
ruby script/console
So just copying / pasting the commands into the .rb file and failing to execute.
Any help would always be appreciated :)
source
share