Class: ActiveAdmin::Cms::Recipe::Ingredient

Inherits:
Object
  • Object
show all
Defined in:
lib/active_admin/cms/recipe/ingredient.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, content_type, opts = {}) ⇒ Ingredient

Returns a new instance of Ingredient.



9
10
11
12
13
# File 'lib/active_admin/cms/recipe/ingredient.rb', line 9

def initialize(id, content_type, opts = {})
  @id = id
  @content_type = content_type
  @options = opts
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



6
7
8
# File 'lib/active_admin/cms/recipe/ingredient.rb', line 6

def content_type
  @content_type
end

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/active_admin/cms/recipe/ingredient.rb', line 6

def description
  @description
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/active_admin/cms/recipe/ingredient.rb', line 6

def id
  @id
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/active_admin/cms/recipe/ingredient.rb', line 6

def options
  @options
end

#sectionObject

Returns the value of attribute section.



6
7
8
# File 'lib/active_admin/cms/recipe/ingredient.rb', line 6

def section
  @section
end

#titleObject

Returns the value of attribute title.



6
7
8
# File 'lib/active_admin/cms/recipe/ingredient.rb', line 6

def title
  @title
end

Instance Method Details

#add_fields_to(formtastic_form) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/active_admin/cms/recipe/ingredient.rb', line 15

def add_fields_to(formtastic_form)
  page = formtastic_form.object
  content = page.content_for content_key
  #debugger
  fields = formtastic_form.fields_for(content) do |i_form|     
    i_form.inputs do
      i_form.input :text
    end
  end
  #debugger
  fields
end

#content_keyObject

returns the key to use for storing content



29
30
31
32
# File 'lib/active_admin/cms/recipe/ingredient.rb', line 29

def content_key
  return "#{section.section_key}:#{id}" if section
  id
end

#input_settings(opts = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/active_admin/cms/recipe/ingredient.rb', line 34

def input_settings opts = {}
  opts[:prefix]
  
  input_options = {:label => title, :input_html => {:name => "content[#{content_key}]", :id => content_key.to_s.gsub(':', '__')}}
  
  input_options[:hint] ||= description if description
  input_options[:hint] ||= content_type.description if !description and !content_type.description.blank?
  input_options.merge! @options if @options
  #debugger
  [
    content_type.input_field,
    input_options.merge(content_type.input_opts)
  ]
end