Requesting and parsing information from another website in Rails
I'm new to Rails and I'm t开发者_StackOverflow社区rying to figure out how to make a request to another website and save the response.
As it stands, I want the user to be able to fill out a form field with a name, press a submit button, and then my app would take the submitted name and form a URL with it. It would then open that URL (Which responds with JSON) and save the JSON it receives. I'm not sure if this should be handled with forms and controllers, jQuery and AJAX, or some mixture of these things. I don't necessarily need a full answer, just a pointer in the direction of some subjects and I should be able to figure it out. Thanks!
Don't go with jQuery and AJAX to get the browser to retrieve the data from the web browser, you'll run into problems with cross site scripting protections (where you're only able to make requests to the same site that the script was downloaded from). There are ways around, but instead:
You can have your form post to your controller, and your controller executes a model's method to retrieve the information from your server, save it, and then display it to the user.
If it's JSON data being returned, I like the HTTParty and Patron gems.
精彩评论