【问题标题】:rake aborted! Don't know how to build task 'sandbox'耙中止!不知道如何构建任务“沙盒”
【发布时间】:2017-07-14 02:13:32
【问题描述】:

我正在尝试将沙盒添加到我的 rails spree 应用程序并遇到此错误 (使用带有 Rails 4.1.6 的 windows 8/powershell)。我会看这本手册: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'

我是 Rails 新手,但我仍然不确定一切是如何运作的,因此需要完整的解释 一步一步的指示将不胜感激!谢谢。

【问题讨论】:

    标签: ruby-on-rails ruby sandbox spree


    【解决方案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?
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-11
      • 1970-01-01
      • 2012-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多