Skip to content

HowTo : Enable view state caching

giniedp edited this page Jul 4, 2012 · 5 revisions

Fancygrid allows to store and load a view state,.

  def index
    fancygrid_for :companies, :persist => true do |g|
      #...
    end
  end

To override the default store an load methods, define the following methods in you controller

def load_fancystate_hash(name)
  session.fetch("fancygrid_#{name}", HashWithIndifferentAccess.new)
end

def store_fancystate_hash(name, state)
  session["fancygrid_#{name}"] = state
end

Since the data is stored in the session it is advisable to enable active record session store.