Note that there are some explanatory texts on larger screens.

plurals
  1. PORails/ActiveRecord Model.Find returns the wrong record
    primarykey
    data
    text
    <p>This is the wackiest.</p> <p>When I visit:</p> <pre><code>/ingredients/14.json </code></pre> <p>I get</p> <pre><code>{ id: 13, name: "Tomato", category: "Vegetable", created_at: "2013-11-20T04:35:36.704Z", updated_at: "2013-11-20T05:59:34.444Z" } </code></pre> <p>And in the logs:</p> <pre><code>Started GET "/ingredients/14.json" for 127.0.0.1 at 2013-11-19 22:02:35 -0800 Processing by IngredientsController#show as JSON Parameters: {"id"=&gt;"14"} Ingredient Load (0.4ms) SELECT "ingredients".* FROM "ingredients" WHERE (14) LIMIT 1 #&lt;Ingredient id: 13, name: "Tomato", category: "Vegetable", created_at: "2013-11-20 04:35:36", updated_at: "2013-11-20 05:59:34"&gt; Completed 200 OK in 18ms (Views: 0.2ms | ActiveRecord: 0.6ms) </code></pre> <p>There are only two items in the database, #13 (tomato) and #14 (egg).</p> <p>I'm using:</p> <ul> <li>Rails 4.0.0</li> <li>SQLite (it's a brand new app :)</li> <li>ActiveModel::Serializers (although I found the same result when I removed the gem and the serializers)</li> <li>Powder (but this continues <em>after</em> <code>powder restart</code>!)</li> <li>Batman.js (but this occurs when Batman requests JSON <strong>and</strong> when I visit the URL with my browser)</li> <li>Chrome (although it also happens in Safari <em>and</em> in Chrome Incognito)</li> </ul> <p>I have no idea what this could be? Any guesses?!</p> <h2>Update</h2> <p>It was just me being an idiot. Check out my bad controller action code:</p> <pre><code> def show @resource = @class.find_by(params[:id]) respond_with @resource end </code></pre> <p>of course, this should be:</p> <pre><code> def show @resource = @class.find(params[:id]) respond_with @resource end </code></pre> <p>Thank you!</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.
 

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