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

当我尝试用耙任务创建计划时,我得到了上面的错误。在正常情况下,我用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

和我的servicescreate_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

有什么办法吗?

解决方案:

你的 stripe.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

给TA打赏
共{{data.count}}人
人已打赏
未分类

我应该如何处理自动刷新令牌?

2022-9-9 7:31:25

未分类

将网页中的HTML转换为XLS

2022-9-9 7:42:17

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索