Cacheable-flash能够和页面缓存一起工作获取Rails闪存对象。这个插件通过在cookie中使用javascript来使用高等级页面缓存,而不是在Rails视图模版中使用高等级页面缓存。同时,Flash内容能够转换成JSON包;通过控制器中的after_filter指令或者是你应用程序中Rack中间层发出信号,Flash内容也能在cookie中被取代。
Cacheable-flash作为一个过滤器使用的时候,你的控制器中必须要包含CacheableFlash模块。无论它是否在你的控制器中发生动作指令,你都不能混淆了闪存信息中的JS和HTML的信息。
请注意,最好刷新页面清除闪存信息,因为cookie上可能会保存未删除之前的内容,页面也将显示未删除之前的内容。
Rspec示例:require "cacheable_flash/test_helpers"class TestController < ActionController::Base def index flash["notice"] = "In index" endenddescribe TestController, "#index" do include CacheableFlash::TestHelpers it "writes to the flash cookie" do get :index flash_cookie["notice"].should == "In index" endend
评论