Module: NoCms::Blocks::BlocksHelper
- Defined in:
- app/helpers/no_cms/blocks/blocks_helper.rb
Instance Method Summary collapse
- #cache_key_for_blocks(block, block_template, options = {}) ⇒ Object
- #render_block(block, options = {}) ⇒ Object
Instance Method Details
#cache_key_for_blocks(block, block_template, options = {}) ⇒ Object
22 23 24 |
# File 'app/helpers/no_cms/blocks/blocks_helper.rb', line 22 def cache_key_for_blocks block, block_template, = {} "#{block_template}/#{block.id}/#{block.updated_at.to_i}#{"/#{[:initial_cache_key]}" unless [:initial_cache_key] }" end |
#render_block(block, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/helpers/no_cms/blocks/blocks_helper.rb', line 4 def render_block block, = {} return if block.draft && ![:force_render_draft] # If we don't have any option about cache enabled then we ask the block [:cache_enabled] = block.cache_enabled unless .has_key? :cache_enabled block_template = "no_cms/blocks/blocks/#{block.template}" # And now decide if we use cache or not if [:cache_enabled] Rails.cache.fetch cache_key_for_blocks(block, block_template, ) do render block_template, block: block end else render block_template, block: block end end |