Sending Post in Ruby

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



Leave a reply



Submit