开发者

Create a script or task to modify database

开发者 https://www.devze.com 2023-03-26 20:35 出处:网络
I need to create 开发者_StackOverflow中文版a script that imports data from a file system source. How do I do that?

I need to create 开发者_StackOverflow中文版a script that imports data from a file system source. How do I do that?

I already tried to create a rake task but there the models are not loaded. How do I get the whole rails environment into my task?


desc 'Do stuff with models'
task :do_stuff => :environment do
  1000.times.each do |i|
    Model.create :name => "model number #{i}"
  end
end

You declare :environment as a dependency of your rake task. This loads up rails and all of your app code before it runs.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号