Note that there are some explanatory texts on larger screens.

plurals
  1. PORails caching remote link_to
    primarykey
    data
    text
    <p>I have a list of items and above it I have a few links that allow you to filter the list but after you click on these links once, WebBrick returns 304 Not Modified. The items in the list can be changed in the list and so these filter links are showing out of date information. My view looks like this:</p> <p>app/views/items/index.html.erb:</p> <pre><code>&lt;%= link_to 'All', {action:'filter', filter:'all'}, remote:true %&gt; &lt;%= link_to 'To Buy', {action:'filter', filter:'to_buy'}, remote:true %&gt; &lt;div id="items"&gt; &lt;%= render 'items' %&gt; &lt;/div&gt; </code></pre> <p>WebBrick is running in development mode so caching shouldn't be turned on. I could set the method to something other than GET but technically that wouldn't be correct. Is there any option to make sure link_to doesn't return cached content? I'm using Rails 3.2.13.</p> <p>app/controllers/items_controller.rb:</p> <pre><code>def filter case params[:filter] when 'to_buy' then @items=Item.where('to_buy=?', true) when 'all' then @items=Item.all end end </code></pre> <p>app/views/items/filter.js.erb:</p> <pre><code>$('#items').html("&lt;%=j render 'items' %&gt;"); </code></pre> <p><strong>UPDATE</strong></p> <p>The only solution I could come up with was to turn the link_tos into normal HTML links and get JQuery to do the ajax request with cache set to false:</p> <p>app/views/items/index.html.erb:</p> <pre><code>&lt;a href="javascript:;" class="filter_link" data-filter="all"&gt;All&lt;/a&gt; &lt;a href="javascript:;" class="filter_link" data-filter="to_buy"&gt;To Buy&lt;/a&gt; </code></pre> <p>app/assets/javascripts/items.js.coffee:</p> <pre><code>$('.filter_link').click -&gt; filter=$(this).data('filter') $.ajax "items/filter/#{filter}", cache:false </code></pre>
    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.
    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