Module: DynMeta::ActionController

Defined in:
lib/dyn_meta/action_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
# File 'lib/dyn_meta/action_controller.rb', line 4

def self.included(base)
  base.class_eval do
    helper_method :meta
  end
end

Instance Method Details

#meta(name, val = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dyn_meta/action_controller.rb', line 10

def meta(name, val = nil)
  
  in_name = "@meta_#{name}"
  return instance_variable_set(in_name, val) if val.present?
  return instance_variable_get(in_name) if instance_variable_get(in_name)
  
  trans = I18n.translate("meta")[name.to_s.pluralize] || {}
  hash = trans
  [:controller, :action, :id].each do |p|
    val = params[p] && hash[params[p].to_s.to_sym] || nil
    if val.nil?
      return instance_variable_set(in_name, hash[:default] || trans[:default] || nil)
    elsif val.is_a?(Hash)
      hash = val
    else
      return instance_variable_set(in_name, val)
    end
  end
end