Hi.. I am using an API. In that, I have to send data in query string. Now my question is how to get back from that site??? because it is not taking return_url from myside. It gives me response. I want to again redirect to some action according to the returned value. It is not allowing me to redirecting multiple times in the same def. I have written following code. <% @url = "www.abc.com/api?name=data" %> <% response = redirect_to(@url) %> <% if response == "true" %> <% redirect_to :action => ''success'' %> <% else %> <% redirect_to :action => ''failure'' %> <% end %> This code gives me error like "multiple redirection". How to solve this??? Thanks.... -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 10, 5:59 am, Smit Shah <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi.. > > I am using an API. In that, I have to send data in query string. Now my > question is how to get back from that site??? because it is not taking > return_url from myside. It gives me response. I want to again redirect > to some action according to the returned value. It is not allowing me to > redirecting multiple times in the same def. > > I have written following code. > > <% @url = "www.abc.com/api?name=data" %> > <% response = redirect_to(@url) %> > <% if response == "true" %> > <% redirect_to :action => ''success'' %> > <% else %> > <% redirect_to :action => ''failure'' %> > <% end %> >First off, this code should not be in a view. Secondly redirect_to just doesn''t work like that. redirect_to sends a response back to the browser that tells it to go to the specified url - you''ll never see the response from that server or indeed the request. If you want to get data out of some 3rd party api then you need to use something like net/http to make an http request. Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Feb 10, 5:59�am, Smit Shah <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> <% @url = "www.abc.com/api?name=data" %> >> <% response = redirect_to(@url) %> >> <% if response == "true" %> >> � <% redirect_to :action => ''success'' %> >> <% else %> >> � <% redirect_to :action => ''failure'' %> >> <% end %> >> > > First off, this code should not be in a view. Secondly redirect_to > just doesn''t work like that. redirect_to sends a response back to the > browser that tells it to go to the specified url - you''ll never see > the response from that server or indeed the request. If you want to > get data out of some 3rd party api then you need to use something like > net/http to make an http request. > > FredThanks Fred.... Can you please post the sample code for the same? Or will you please provide links than can help me out? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
You need to send a http request in the controller action and use that info to redirect the user. require ''net/http'' connection = Net::HTTP.new("www.google.com") response = "" connection.start do |http| req = Net::HTTP::Get.new("/#hl=en&source=hp&q=ruby+on+rails&aq=f&aqi=g10&oq=&fp=c26c79a56c95bda8") response = http.request(req) end if(response == "true") redirect_to(:action => ''success'') else redirct_to(:action => ''failure) end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.