Note that there are some explanatory texts on larger screens.

plurals
  1. POformat json in rails3
    primarykey
    data
    text
    <p>I'm trying to access a JSON version of my variable. I tried using . notation on the shows variable as I presumed it was now formatted as a json object. @shows.title but that caused an error. I tried to use @shows.to_json.title for it to work but still no good. I thought when you format.json it already calls the to_json and that was the idea of using format or am in incorrect in thinking this way. If so what does format do then. </p> <pre><code> class ShowsController &lt; ApplicationController # GET /shows # GET /shows.json def index @shows = Show.all respond_to do |format| format.html # index.html.erb format.json { render json: @shows } end end </code></pre> <p>index.html.erb</p> <pre><code>&lt;p&gt; @shows.title &lt;p&gt; </code></pre> <p>the structure I'm looking for in JSON would be like this.</p> <pre><code>[ { "id": "feature", "width":570, "title": "Lorem ipsum dolor amet emipsum do omnis iste natus", "description": "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantiu mdoloremque laudantium.", "img": "img/work/img1.jpg", "url": "http://www.bla.com" }, { "id": "show", "width":200, "title": "Lorem ipsum dolo", "description": "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantiu mdoloremque laudantium.", "img": "img/work/img2.jpg", "url": "http://www.bla.com" } </code></pre> <p>]</p> <p><strong>UPDATED:</strong> maybe I'm not explaining this correctly. </p> <p>My goal here is to have my action in the controller call the index.html page, which it does now. On that page is a jquery plugin that requests a JSON object with all the data from the database. This way it can parse through the JSON and render all the objects on the index.html page using jquery plugin. The reason for this is it's using a plugin called jquery.masonry.js &amp; jquery.infinitescroll.js which is now setup to use multiple JSON structures to create my pages. </p>
    singulars
    1. This table or related slice is empty.
    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.
 

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