简体   繁体   English

保存到数据库中,但在Ruby on Rails中检查http请求之前

[英]Save to database post,but before check http request in Ruby on Rails

I am trying save hashes to my database but before I want check request I am using 我正在尝试将哈希保存到我的数据库中,但是在我想要检查请求之前,我正在使用

require 'net/http'
gem 'http'

This is my controller (hashes I call :hammer) 这是我的控制器(我称其为:hammer的哈希)

class PaymentsController < ApplicationController
  before_action :logged_in_user, only: [:create]

  def create
    @payment = current_user.payments.build(payment_params)
    aza = ''
    uri = URI("https://blockexplorer.com/api/tx/#{:hammer}")
    res = Net::HTTP::Post.new(uri)
    res1 = res.class.name
    aza += Net::HTTP.get(uri)
    @go = aza
    if aza.include?( '3MGeicHK6P2pUpepsXyTiuA7omMbRZbZx3') #'"addresses":["3MGeicHK6P2pUpepsXyTiuA7omMbRZbZx3"]'
      if aza.include? '"value":"0.03072025"'
        if aza.include? '"confirmations":0'
          flash[:info] = "Wait 15 minutes for confirm"
        else
          if @payment.save
            flash[:success] = "You paid"
            redirect_to root_url
          else
            render 'welcome/index'
          end
        end
      else
        flash[:danger] = "You paid less"
      end
    else
      flash[:danger] = "#{res1}"
      redirect_to root_url
    end
  end

  def destroy
  end

  private

  def payment_params
    params.require(:payment).permit(:hammer)
  end
end

When I was try to save it is not check, it is just show error 400 But If I use console it is work 当我尝试保存它时不检查,它只是显示错误400,但是如果我使用控制台,那是可行的

uri = URI("https://blockexplorer.com/api/tx/f484f14ebf9726ab2ab46ffc491786db50fc69ceff737620122e51559a3ea379")
irb(main):003:0> Net::HTTP.get(uri)

I find want can to do 我发现想做

      @test = payment_params[:hammer]
   #   hammer = ''
   #   hammer += params[:hammer].to_s
      aza = ''
      uri = URI("https://blockexplorer.com/api/tx/#{@test}")

I think the bug is there: 我认为错误存在:

uri = URI("https://blockexplorer.com/api/tx/#{:hammer}")

in PaymentsController. 在PaymentsController中。 Try that instead: 尝试改用:

uri = URI("https://blockexplorer.com/api/tx/#{params[:hammer]}")

You missed params[] in your interpolation. 您在插值中错过了params []。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM