Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

html - Post and redirect to external site from Rails controller?

After the user registration page, web clients will come to this page, which contains only a proceed button. But I want to skip this page and proceed to the payment page. Is there any way to do this action completely in the controller?

<form method="post" action="https://www.ccavenue.com/shopzone/cc_details.jsp">
    <input type=hidden name=Merchant_Id value="<%= @Merchant_id %>">
    <input type=hidden name=Amount value="<%= @Amount %>">
    <input type=hidden name=Order_Id value="<%= @user_id %>">
    <input type=hidden name=Redirect_Url value="<%= @redirect_url %>">
    <input type=hidden name=Checksum value="<%= @checksum %>">
    <input type="submit" class="Register_button" value="Proceed to payment">
</form>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should do POST request from controller.

uri = URI.parse("https://www.ccavenue.com/shopzone/cc_details.jsp")
http = Net::HTTP.new(uri.host, uri.port)

form_data = {
  "Merchant_Id" => @Merchant_id,
  "Amount" => @Amount,
  "Order_Id" => @user_id,
  "Redirect_Url" => @redirect_url,
  "Checksum" => @checksum
}

request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data(form_data)

response = http.request(request)

You can use httparty gem to do post request.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...