sending POST in ruby?
You can do something like this...
require 'net/http'
postData = Net::HTTP.post_form(URI.parse('http://thewebsite.net'), {'postKey'=>'postValue'})
puts postData.body
Sending POST request rails
Your POST
from postman app should be structured to be something like this:
beer[name] testing
beer[percent] 1
Send POST request to another action
No need to post to another action here, just follow the rails pattern (if you've ever scaffolded a new resource, you should have seen this before):
def download
url = Url.new(params[:url])
if url.save
redirect_to happy_route
else
redirect_to unhappy_route
end
end
how send post request and open url in Ruby Sinatra
If you want to directly pass along a POST request and redirect to it, you can do
post '/send' do
redirect <your_url>, 307
end
307
is the HTTP status code to not modify the request method.
Handle a redirect response like this:
post '/send' do
# post form
redirect response['location'], 302
end
How to send post request to rails action
Yuna you will need to output response in json. lets assume that your ajax script can send data to ruby on rails backend properly.
Try this
at ajax
not this
url:"/responses/",
but
url:"/responses.json",
you can then get result as per
alert("success" + result.myurl);
you can myurl as part of the json response
Finally try this
def index
respond_to do |format|
#@url = params[:option]
@url='nancy more url'
format.json do
render json: {myurl: @url}.to_json
end
end
end
Related Topics
How to Tell Which Openssl Lib Is Actually Being Used by an Rvm-Installed Ruby
Open-Uri Returning Ascii-8Bit from Webpage Encoded in Iso-8859
In Rails, How to Access Response.Body in a Action Before It Returns
Wicked_Pdf: Footer Height/Styling
Multiple Level Nesting in Yaml
Specifying Content Type in Rspec
How to Require a Block in Ruby
Suppresing Output to Console with Ruby
Case Expression Different in Ruby 1.9
Custom_Require.Rb:36:In 'Require': No Such File to Load -- Myapp(Loaderror)
Saml 2.0 Sso for Ruby on Rails
Openssl Trouble with Ruby 1.9.3
Implementing a Synchronization Barrier in Ruby
Ruby on Rails: How to Use Oauth2::Accesstoken.Post
Generate Array of Numbers That Fit to a Probability Distribution in Ruby