Ruby 1.8.7 を実行している Rails 3.2.6 アプリケーションでフラグメント キャッシュを使用しています。
私のコントローラーには次のものがあります:
class ProductsController < ApplicationController
cache_sweeper :product_sweeper
スイーパーは C-UD アクションでは機能しますが、私の POST メソッド「changeorder」では機能しません。
私は試した:
cache_sweeper :product_sweeper, :only =>
すべての C-UD と :changeorder を追加しましたが、うまくいきませんでした。
これをスイーパーに追加しました:
def after_product_changeorder(product)
expire_cache(product)
end
エラーにはなりませんが、どちらも機能しません。product_ を削除しましたが、エラーは発生せず、機能しませんでした。
_product* s * に変更しましたが、エラーが発生しました。
フラグメントを期限切れにする唯一の方法は、次のものを使用することでした。
expire_fragment('page_home')
変更順序コントローラ メソッドで。
記録のために、ここに私のスイーパーがあります:
class ProductSweeper < ActionController::Caching::Sweeper
observe Product
def after_save(product)
expire_cache(product)
end
def after_destroy(product)
expire_cache(product)
end
private
def expire_cache(product)
# expire_page products_path
# expire_page product_path(product)
expire_fragment('page_home')
end
end
そして私のコントローラーメソッド:
def changeorder
params[:product].each_with_index do |id, index|
Product.update_all(['displayorder=?', index+1], ['id=?', id])
end
render :nothing => true
end
そして私のルートファイル - 役に立つかもしれません:
resources :products do
collection do
post 'changeorder'
end
end
「changeorder」を PUT に変更しましたが、それでも違いはありませんでした。
ここに何かアイデアはありますか?私はSOページのスタックロードを経験してきましたが、機能するものは何も見つかりませんでした.他の分野で役立つものをたくさん見つけたので、私の側で時間を無駄にすることはありません.