【发布时间】:2017-09-06 07:59:15
【问题描述】:
我正在尝试将哈希值保存到我的数据库中,但在我想要检查请求之前 我正在使用
require 'net/http'
gem 'http'
这是我的控制器(我称之为: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
当我尝试保存时没有检查,它只是显示错误 400 但如果我使用控制台,它就可以工作
uri = URI("https://blockexplorer.com/api/tx/f484f14ebf9726ab2ab46ffc491786db50fc69ceff737620122e51559a3ea379")
irb(main):003:0> Net::HTTP.get(uri)
【问题讨论】:
标签: ruby-on-rails ruby database save httprequest