jeudi 2 avril 2015

Rails Caching with query parameters

I'm trying to use fragment caching in my rails application. It seems to be working ok except in views that use query parameters to filter this content. When I ever I click to view version rather 'main' or 'test' it always show the same main build even when there no test builds and the param is set to 'test'.


index.html.erb



<% if browser.mobile? %>
<% cache(params[:version_type], controller: 'versions', action: 'index', action_suffix: "#{@version_type}_versions_mobile") do %>
<%= render partial: 'mobile', locals: { versions: @versions, version_type: @version_type } %>
<% end %>
<% else %>
<% cache(params[:version_type], controller: 'versions', action: 'index', action_suffix: "#{@version_type}_versions_full") do %>
<%= render partial: 'full', locals: { versions: @versions } %>
<% end %>
<% end %>


versions_controller.rb



class VersionsController < ApplicationController
def index
@version_type = params['version_type'] || 'main'
app_id = params['app_id']
if iphone?
@versions = Version.order(created_at: :desc).includes(:app)
.where(app_id: app_id, iphone_support: true,
version_type: @version_type)
elsif ipad?
@versions = Version.order(created_at: :desc).includes(:app)
.where(app_id: app_id, ipad_support: true)
elsif android?
@versions = Version.order(created_at: :desc).includes(:app)
.where(app_id: app_id)
else
@versions = Version.order(created_at: :desc)
.includes(:app).where(app_id: app_id)
end
end
end

Aucun commentaire:

Enregistrer un commentaire