2015-09-05 92 views
0

当我尝试使用rake任务创建计划时,出现上述错误。 在平常的时间里,我使用导轨控制台来完成它,但我必须以另一种方式来完成。不知道如何构建任务'stripe:create_plans'

用命令:

$ 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 

任何想法?

回答

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 
+0

就是这样,谢谢! –

+0

@TimothéGauguet,你能接受吗? –

相关问题