耙子流产了!不知道如何构建任务'沙盒'

时间:2014-10-14 21:33:06

标签: ruby-on-rails ruby sandbox spree

我试图将沙箱添加到我的rails spree应用程序并遇到此错误 (使用Windows 8 / powershell和Rails 4.1.6)。我将阅读本手册:https://github.com/spree/spree/issues/411

此链接Use older version of Rake 似乎有类似的问题,但我不知道如何采取必要的步骤来实现它。

当我尝试:

C:\Ruby193\openUpShop> bundle exec rake sandbox

我明白了:

rake aborted!
Don't know how to build task 'sandbox'

我是铁杆的新手,我仍然不确定一切是如何工作的,所以在整个解释中 一步一步的说明将不胜感激!谢谢。

1 个答案:

答案 0 :(得分:1)

您可以使用文件sandbox.rb

# use example: rake task:sub_task -- --sandbox

if ARGV.any? {|arg| arg == '--sandbox' }
  puts "** << USING SANDBOX!! >> **"

  # beginning
  $sandbox = -> do
    ActiveRecord::Base.connection.begin_transaction
  end

  # end
  at_exit do
    ActiveRecord::Base.connection.rollback_transaction
  end
end

然后只需要在task.rake文件的开头添加

require_relative 'path_to_your/sandbox.rb'

..并在任务代码的开头添加

desc "description task"
task example_task: :environment do
    $sandbox.call if $sandbox.present?
...
相关问题