Reputation: 99
I am trying to modify my database in rails for that I want to write a script that would modify my model accordingly when executed. I have no idea how to create a script and run it using rails console. Please somebody guide me.
Eg -: Suppose i want to write a script that has Model.all written in it and when I execute it using console Model.all should run
Upvotes: 0
Views: 1945
Reputation: 2522
Use Rails tasks instead:
namespace :mytasks do
desc "This is a Hello world task. All it does it say hello"
task :hello => :environment do
puts "Hello!"
end
end
Then in the console you do:
rake mytasks:hello
Upvotes: 2
Reputation: 5204
One the quick temporary solution adds a new class method to your Model:
class Model
def self.modify_db
Model.find_each do |item|
end
end
end
In console just type: Model.modify_db
Upvotes: 0