Reputation: 1456
I have a form_tag
with some text_field_tag
, what I wanted is that when I submit the form through Ajax it goes to a specific action of specific controller, where I am using rest_client gem to hit a specific URL and get response from that URL and send that response in ajax request.
But when the form is submitted and goes to specific action where rest client suppose to process a GET
request
(which is basically a request to another controller of same application)
and return some response so that I can render that json response in ajax request but I always get Timeout error, I have already tried by changing timeout but didnot get success.
I am able to get response from rest_client when I run that request in rails console
.
Upvotes: 0
Views: 267
Reputation: 37409
It seems that you are running your rails application on a single-thread container (like WebBrick). This means that the server can only deal with a single request at a time.
In your use case the request is initiated in the controller, and the RestClient call is issued, and then it is stuck in the queue of the server waiting for the previous call to finish processing, effectively dead-locking your web-server.
When you run the RestClient call from the rails console
, the server does not have any request processing, so the call passes.
You can deal with this by changing your architecture to enable receiving multiple requests (using EventMachine, or running your app on a unicorn
server), but it does still smell. I suggest you figure out a way to call the logic of the other controller without issuing a new web request to yourself, which is an overkill, with a lot of overhead.
Upvotes: 1