Module: Annex::ViewHelpers
- Defined in:
- lib/annex/view_helpers.rb
Overview
Create global view helpers
Instance Method Summary collapse
-
#annex_block(identifier, opts = {}) ⇒ Object
annex_block is a universal helper to render content from the database and display it on the page.
- #current_route ⇒ Object
Instance Method Details
#annex_block(identifier, opts = {}) ⇒ Object
annex_block is a universal helper to render content from the database and display it on the page
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/annex/view_helpers.rb', line 10 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 |
#current_route ⇒ Object
28 29 30 |
# File 'lib/annex/view_helpers.rb', line 28 def current_route "#{I18n.locale}_#{params[:controller]}_#{params[:action]}".to_sym end |