Module: Cells::Rails::ActionController

Defined in:
lib/cells/rails.rb

Instance Method Summary collapse

Instance Method Details

#expire_cell_state(cell_class, state, args = {}, opts = nil) ⇒ Object

Expires the cached cell state view, similar to ActionController::expire_fragment. Usually, this method is used in Sweepers. Beside the obvious first two args cell_name and state you can pass in additional cache key args and cache store specific opts.

Example:

class ListSweeper < ActionController::Caching::Sweeper
 observe List, Item

 def after_save(record)
   expire_cell_state :my_listing, :display_list
 end

will expire the view for state :display_list in the cell MyListingCell.



39
40
41
42
43
44
45
46
47
# File 'lib/cells/rails.rb', line 39

def expire_cell_state(cell_class, state, args={}, opts=nil)
  if cell_class.is_a?(Symbol)
    ActiveSupport::Deprecation.warn "Please pass the cell class into #expire_cell_state, as in expire_cell_state(DirectorCell, :count, :user_id => 1)"
    cell_class = Cell::Base.class_from_cell_name(cell_class)
  end
  
  key = cell_class.state_cache_key(state, args)
  cell_class.expire_cache_key(key, opts)
end

#render_cell(name, state, *args, &block) ⇒ Object

Renders the cell state and returns the content. You may pass options here, too. They will be around in @opts.

Example:

@box = render_cell(:posts, :latest, :user => current_user)

If you need the cell instance before it renders, you can pass a block receiving the cell.

Example:

@box = render_cell(:comments, :top5) do |cell|
  cell.markdown! if config.parse_comments?
end


20
21
22
# File 'lib/cells/rails.rb', line 20

def render_cell(name, state, *args, &block)
  ::Cell::Base.render_cell_for(self, name, state, *args, &block)
end