开发者

Create a script or task to modify database

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜