不知道如何构建任务' stripe:create_plans'

时间:2015-09-05 12:35:06

标签: ruby-on-rails ruby

当我尝试使用rake任务创建计划时,我得到了上面的错误。 在正常的时间,我使用rails控制台,但我必须以另一种方式。

使用命令:

$ rake stripe:create_plans --trace
rake aborted!
Don't know how to build task 'stripe:create_plans'
/Users/Tim/.rvm/gems/ruby-1.9.3-p551/gems/rake-10.4.2/lib/rake/task_manager.rb:62:in `[]'
/Users/Tim/.rvm/gems/ruby-1.9.3-p551/gems/rake-10.4.2/lib/rake/application.rb:149:in `invoke_task'
/Users/Tim/.rvm/gems/ruby-1.9.3-p551/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/Tim/.rvm/gems/ruby-1.9.3-p551/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/Users/Tim/.rvm/gems/ruby-1.9.3-p551/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/Users/Tim/.rvm/gems/ruby-1.9.3-p551/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/Users/Tim/.rvm/gems/ruby-1.9.3-p551/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/Users/Tim/.rvm/gems/ruby-1.9.3-p551/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/Users/Tim/.rvm/gems/ruby-1.9.3-p551/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/Tim/.rvm/gems/ruby-1.9.3-p551/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/Users/Tim/.rvm/gems/ruby-1.9.3-p551/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
/Users/Tim/.rvm/gems/ruby-1.9.3-p551/bin/rake:23:in `load'
/Users/Tim/.rvm/gems/ruby-1.9.3-p551/bin/rake:23:in `<main>'
/Users/Tim/.rvm/gems/ruby-1.9.3-p551/bin/ruby_executable_hooks:15:in `eval'
/Users/Tim/.rvm/gems/ruby-1.9.3-p551/bin/ruby_executable_hooks:15:in `<main>'

这是我的stripe.rake文件:

task :stripe do
 desc "Create stripe plans"
 task :create_plans => :environment do
   CreatePlan.call(stripe_id: 'test_plan', name: 'Test Plan', amount: 500, interval: 'month', description: 'Test Plan', published: true)
 end
end

和我的服务/ create_plan.rb:

class CreatePlan
def self.call(options={})
    plan = Plan.new(options)

    if !plan.valid?
    return plan
end

begin
    Stripe::Plan.create(
                    id: options[:stripe_id],
                    amount: options[:amount],
                    currency: 'eur',
                    trial_period_days: options[:trial_period_days],
                    interval: options[:interval],
                    interval_count: options[:interval_count],
                    name: options[:name],
                    price: options[:price],
                    )
                    rescue Stripe::StripeError => e
                    plan.errors[:base] << e.message
                    redirect_to :action => :index
    end
    plan.save

    redirect_to :action => :index
end
end

有什么想法吗?

1 个答案:

答案 0 :(得分:4)

您的strip.rake文件应为

namespace :stripe do
    desc "Create stripe plans"
    task :create_plans => :environment do
        CreatePlan.call(stripe_id: 'test_plan', name: 'Test Plan', amount: 500, interval: 'month', description: 'Test Plan', published: true)
    end
end