Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 条带:参数丢失或值为空:费用_Ruby On Rails_Ruby_Ruby On Rails 4_Rails Activerecord_Stripe Payments - Fatal编程技术网

Ruby on rails 条带:参数丢失或值为空:费用

Ruby on rails 条带:参数丢失或值为空:费用,ruby-on-rails,ruby,ruby-on-rails-4,rails-activerecord,stripe-payments,Ruby On Rails,Ruby,Ruby On Rails 4,Rails Activerecord,Stripe Payments,我正试图找出如何将自定义条带表单集成到barebones rails应用程序中,但到目前为止,这是一段艰难的时间 我遇到错误:param丢失或值为空:费用 这是我的收费管理员: class ChargesController < ApplicationController def new @charge = Charge.new end def create @charge = Charge.new if @charge.ch

我正试图找出如何将自定义条带表单集成到barebones rails应用程序中,但到目前为止,这是一段艰难的时间

我遇到错误:
param丢失或值为空:费用

这是我的收费管理员:

class ChargesController < ApplicationController

    def new
      @charge = Charge.new
    end

    def create
      @charge = Charge.new
      if @charge.charging_card(charges_params)
        redirect_to root_path, :notice => "Contribution was recorded succesfully!"
      else
        redirect_to about_path, :notice => "Transaction was not able to be recorded"
      end
    end

    def charges_params
        params.require(:charges).permit(:stripe_card_token)
    end


end
这是我的服务器日志:

Started POST "/charges" for 127.0.0.1 at 2014-07-23 01:57:45 -0700
Processing by ChargesController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"4FJAw5RTi1K2n3mC0lccoJ2iaDeQxfXRMGqi2kojsbk=", "date"=>{"month"=>"1",
 "year"=>"2015"}, "commit"=>"Donate"}
Completed 400 Bad Request in 4ms

ActionController::ParameterMissing (param is missing or the value is empty: charge):
  app/controllers/charges_controller.rb:17:in `charges_params'
  app/controllers/charges_controller.rb:9:in `create'


  Rendered c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/template
s/rescues/_source.erb (71.0ms)
  Rendered c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/template
s/rescues/_trace.html.erb (4.0ms)
  Rendered c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/template
s/rescues/_request_and_response.html.erb (3.0ms)
  Rendered c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/template
s/rescues/diagnostics.erb within rescues/layout (221.1ms)
我想我不明白为什么强参数中的电荷是空的


任何其他的建议或建议,你可以从我的代码,可以帮助我完成这个项目将不胜感激

尝试将强参数更改为以下内容:

def charges_params
  if params[:charges] && params[:charges][:stripe_card_token].present?
    params.require(:charges).permit(:stripe_card_token)
  end
end

你能发布你生成的服务器日志吗?@Pavan我刚刚在问题的末尾添加了我的日志输出。谢谢。这一行
@charge=charge.new
在你的创建操作中应该是
@charge=charge.new(charge\u params)
我猜。我没有看到
在你的
创建
操作中的
保存
,如果@charge.charge\u params)
卡(charge\u params)
怎么办?当我做@charge=charge.new(charge\u params)时我一访问我的“费用”视图就会出错。。我得到以下信息:param丢失或值为空:chargeThat worked。。为什么会这样?不幸的是,现在我在日志中看到另一个问题,即“创建客户时出现条带错误:您必须提供卡或客户id”,因为您没有发送参数“费用”来创建
ActiveRecord::Schema.define(version: 20140723082502) do

  create_table "charges", force: true do |t|
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "stripe_card_token"
    t.decimal  "amount"
  end

end
Started POST "/charges" for 127.0.0.1 at 2014-07-23 01:57:45 -0700
Processing by ChargesController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"4FJAw5RTi1K2n3mC0lccoJ2iaDeQxfXRMGqi2kojsbk=", "date"=>{"month"=>"1",
 "year"=>"2015"}, "commit"=>"Donate"}
Completed 400 Bad Request in 4ms

ActionController::ParameterMissing (param is missing or the value is empty: charge):
  app/controllers/charges_controller.rb:17:in `charges_params'
  app/controllers/charges_controller.rb:9:in `create'


  Rendered c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/template
s/rescues/_source.erb (71.0ms)
  Rendered c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/template
s/rescues/_trace.html.erb (4.0ms)
  Rendered c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/template
s/rescues/_request_and_response.html.erb (3.0ms)
  Rendered c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/template
s/rescues/diagnostics.erb within rescues/layout (221.1ms)
def charges_params
  if params[:charges] && params[:charges][:stripe_card_token].present?
    params.require(:charges).permit(:stripe_card_token)
  end
end