Sha256: d4e46d4698c52cc5af89a7f45837089ac85768c221d643f100a63ca6d5e54acf
Contents?: true
Size: 855 Bytes
Versions: 10
Compression:
Stored size: 855 Bytes
Contents
module Annex # # Create global view helpers # module ViewHelpers # # annex_block is a universal helper to render content from # the database and display it on the page # def annex_block(identifier, opts = {}) opts[:route] ||= current_route case Annex::config[:adapter] when :activerecord doc = Annex::Block.where(route: "#{opts[:route]}_#{identifier}").first_or_create content = doc.content when :mongoid doc = Annex::Block.where(route: opts[:route]).first_or_create content = doc.content.try(:[], identifier.to_s) end render partial: 'annex/block', locals: { content: content || opts[:default], identifier: identifier, opts: opts } end def current_route "#{I18n.locale}_#{params[:controller]}_#{params[:action]}".to_sym end end end
Version data entries
10 entries across 10 versions & 1 rubygems