Hi- I have a rails app where a form gets submitted, and that data from the form has to be validated. It''s a widget app, so other sites will use the validation routine, but I also want to use it myself, from the same server that does the validation. So, is it possible for a ruby instance to send a post to the same server? I try this in development but it freezes up and I eventually get a timeout error. The code looks like this: def verify_home @response = "An error has occurred." if params[:widget_id] and params[:widget_answer] result = Net::HTTP.post_form(URI.parse(''http://localhost:3000/ questions/verify''), {''widget_id'' => params[:widget_id], ''widget_answer'' => params[:widget_answer]) if result.include? "success" @response = "Correct!" end end redirect_to :action => "index" end So, the "questions/verify" method works just fine on its own (when submitted from a different site), but freezes up when I send it from the current server to itself. Any advice? Thanks, Dino -- 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 26, 2010, at 11:29 AM, dino d. wrote:> Hi- > > I have a rails app where a form gets submitted, and that data from the > form has to be validated. It''s a widget app, so other sites will use > the validation routine, but I also want to use it myself, from the > same server that does the validation. So, is it possible for a ruby > instance to send a post to the same server? I try this in development > but it freezes up and I eventually get a timeout error. The code > looks like this: > > def verify_home > @response = "An error has occurred." > if params[:widget_id] and params[:widget_answer] > result = Net::HTTP.post_form(URI.parse(''http://localhost:3000/ > questions/verify''), > {''widget_id'' => params[:widget_id], ''widget_answer'' => > params[:widget_answer]) > if result.include? "success" > @response = "Correct!" > end > end > redirect_to :action => "index" > end > > So, the "questions/verify" method works just fine on its own (when > submitted from a different site), but freezes up when I send it from > the current server to itself. > > Any advice?Any chance you are using webrick? Webrick is single threaded and won''t handle multiple requests at the same time. Try running it with mongrel or something else that can handle multiple requests at the same time. There''s no reason you can''t do what you''re trying to do. Although, if you''re verifying against yourself it will be a lot faster to call the ruby method/routine that does it instead of posting back to yourself. Net::HTTP is slow. -philip -- 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 26, 2:29 pm, "dino d." <dinodorr...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Hi- > > I have a rails app where a form gets submitted, and that data from the > form has to be validated. It''s a widget app, so other sites will use > the validation routine, but I also want to use it myself, from the > same server that does the validation. So, is it possible for a ruby > instance to send a post to the same server? I try this in development > but it freezes up and I eventually get a timeout error. The code > looks like this: > > def verify_home > @response = "An error has occurred." > if params[:widget_id] and params[:widget_answer] > result = Net::HTTP.post_form(URI.parse(''http://localhost:3000/ > questions/verify''), > {''widget_id'' => params[:widget_id], ''widget_answer'' => > params[:widget_answer]) > if result.include? "success" > @response = "Correct!" > end > end > redirect_to :action => "index" > end > > So, the "questions/verify" method works just fine on its own (when > submitted from a different site), but freezes up when I send it from > the current server to itself.You''re probably better off just calling the model method that questions/verify calls - you could even refactor the parameter parsing into a method on ApplicationController if verify_home isn''t in the same class. --Matt Jones -- 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.