Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Rails 3.1.x already returns JSON requests if you have a controller like this:</p> <pre><code>class EaracheMyEyeController &lt; ApplicationController def show @earache_my_eye = EaracheMyEye.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render json: @earache_my_eye } end end end </code></pre> <p>The <code>format.json { render json: @earache_my_eye }</code> part will render the data as JSON if you visit the URL of the object, for example <code>earachemyeyes/1.json</code> </p> <p>So, in your phone gap app you would call URLS GET method to receive data and add on <code>.json</code> on the end of the url to receive JSON formatted data. </p> <p>Update:</p> <p>A few things I learned recently about JSONP requests in phonegap. They are <em>only</em> GET requests. No posts. </p> <p>However, you can append a <code>_method=POST</code>, and add <code>configure.middleware.swap(Rack::MethodOverride,Rack::RestfulJsonpMiddleware</code> to your conf/environments/(production/development/test).rb file(s) </p> <p>Add something like this to your library:</p> <p><a href="https://github.com/quickleft/kbomb_phonegap_server/blob/master/lib/rack/restful_jsonp_middleware.rb" rel="nofollow">https://github.com/quickleft/kbomb_phonegap_server/blob/master/lib/rack/restful_jsonp_middleware.rb</a></p> <p>This allows you to send an actual GET request, yet it is read and processed as your <code>_method=POST</code> or whatever method you really need. You can't use the built in Rack::MethodOverride because it only implements POST, and nothing else (was meant to facilitate PUT and GET). So the file at <a href="https://github.com/quickleft/kbomb_phonegap_server/blob/master/lib/rack/restful_jsonp_middleware.rb" rel="nofollow">https://github.com/quickleft/kbomb_phonegap_server/blob/master/lib/rack/restful_jsonp_middleware.rb</a> builds a new Rack middleware that lets you use all HTTP methods.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload