Ruby on Rails POST parameters on redirect_to

后端 未结 3 1446
花落未央
花落未央 2021-01-07 08:42

I have to make a call to a different url in one of my controllers on my site. The problem is that with all the parameters the other site requires I\'m overflowing the url.

相关标签:
3条回答
  • 2021-01-07 08:58

    This is from the ruby docs:

    require 'net/http'
    require 'uri'
    
    result = Net::HTTP.post_form(URI.parse('http://www.example.com/search.cgi'),
        {'q'=>'ruby', 'max'=>'50'})
    

    As you can see, you pass the params in as a convenient hash, unlike other languages that make you mess with http formatting.

    0 讨论(0)
  • 2021-01-07 09:06

    You can't do a redirect and send POST data at the same time in the HTTP spec. Redirects are implemented by sending a simple Location: otherlocation.html header. POST data doesn't fit anywhere into that system.

    Do you want the user to go to this page, or do you want to just send the data to the application yourself? If you want to send the data and not send the user there, use Ruby's Net::HTTP module. If you want to send the user, you may be forced to output a view with a form, and submit it automatically with Javascript. (Don't forget to degrade gracefully by offering a submit button in noscript tags.)

    0 讨论(0)
  • 2021-01-07 09:14

    You can also use the flash to transfer the information. http://guides.rubyonrails.org/action_controller_overview.html#the-flash

    0 讨论(0)
提交回复
热议问题