Note that there are some explanatory texts on larger screens.

plurals
  1. PORails.cache.fetch exception: TypeError (<ModelName> can't be referred to)
    primarykey
    data
    text
    <p>I'm implementing some caching by using the nifty <code>Rails.cache.fetch</code>. However, in one particular instance, sometimes I encounter an exception:</p> <pre class="lang-none prettyprint-override"><code>TypeError in EmloController#index Emlo can't be referred to app/controllers/emlo_controller.rb:320:in `get_employees' app/controllers/emlo_controller.rb:356:in `prepare_json_response' app/controllers/emlo_controller.rb:23:in `block (2 levels) in index' app/controllers/emlo_controller.rb:15:in `index' </code></pre> <p>It seems the fetch will always explode (with the above) on the first try, and then work fine as long as the fetch is within the expiration. I know I'm missing something, so a fresh pair of eyes would be nice.</p> <p>Here's the method which invokes the cache fetch:</p> <pre class="lang-ruby prettyprint-override"><code>def get_employees # This is for a AJAX refresh loop, so a 5-second cache actually helps quite a bit Rails.cache.fetch('emlo_all', :expires_in =&gt; 5.seconds, :race_condition_ttl =&gt; 1) do conditions = (params[:id]) ? {:user_id =&gt; params[:id]} : nil selections = [ 'employee_locations.id AS emlo_id', 'employee_locations.status_id', 'employee_locations.notes', 'employee_locations.until', 'employee_locations.updated_at', 'employee_locations.user_id', 'location_states.id AS state_id', 'location_states.title AS status_string', 'location_states.font_color', 'location_states.bg_color', 'users.displayname', 'users.email', 'users.mobile', 'users.department', 'users.extension', 'users.guid', 'users.dn' ].join(', ') Emlo.all( :select =&gt; selections, :joins =&gt; 'LEFT JOIN users ON employee_locations.user_id=users.id LEFT JOIN location_states ON employee_locations.status_id=location_states.id', :conditions =&gt; conditions, :order =&gt; 'users.displayname ASC' ) end end </code></pre>
    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