简体   繁体   中英

Send and retrieve Ruby on Rails query?

I don't know anything about Ruby, but I think what I'm trying to do is pretty simple. I have an app that needs to send a url query like this to a heroku database: http://dartmouth.heroku.com/dnd/search.json?query=sebastian , then receive the data that comes back and organize it for the user. How do I send and recieve a query like this?

EDIT: I downloaded Spring and added the rest template jar to my projects build path. I tried using this code:

String url = "http://dartmouth.heroku.com/dnd/" + dataBase + "json?query=" + searchContent;
RestTemplate rstTemplate = new RestTemplate();
PersonList pList = rstTemplate.getForObject(url, PersonList.class);

but "RestTemplate" is not recognized. Did I miss an installation step?

You need to start by making an HTTP request for the data and then parsing the results. I would suggest trying out the Spring Android library to accomplish this: http://www.springsource.org/spring-android

Check out the explanation here: http://mike.bailey.net.au/2011/02/json-with-ruby-and-rails/

You can use a plugin called HttpParty for sending the request. Ruby on rails will interpret the json response by using the json library. The example on the above mentioned page might make things clearer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM