Class: Crystal::ModelHelper

Inherits:
Object show all
Defined in:
lib/crystal/html/view_helpers/model_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, form_helper, model_name, model, options) ⇒ ModelHelper

Returns a new instance of ModelHelper.



5
6
7
# File 'lib/crystal/html/view_helpers/model_helper.rb', line 5

def initialize template, form_helper, model_name, model, options
  self.template, self.form_helper, self.model_name, self.model, self.options = template, form_helper, model_name, model, options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &b) ⇒ Object (protected)



66
67
68
# File 'lib/crystal/html/view_helpers/model_helper.rb', line 66

def method_missing m, *args, &b
  form_helper.send m, *args, &b
end

Instance Attribute Details

#form_helperObject

Returns the value of attribute form_helper.



3
4
5
# File 'lib/crystal/html/view_helpers/model_helper.rb', line 3

def form_helper
  @form_helper
end

#modelObject

Returns the value of attribute model.



3
4
5
# File 'lib/crystal/html/view_helpers/model_helper.rb', line 3

def model
  @model
end

#model_nameObject

Returns the value of attribute model_name.



3
4
5
# File 'lib/crystal/html/view_helpers/model_helper.rb', line 3

def model_name
  @model_name
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/crystal/html/view_helpers/model_helper.rb', line 3

def options
  @options
end

#templateObject

Returns the value of attribute template.



3
4
5
# File 'lib/crystal/html/view_helpers/model_helper.rb', line 3

def template
  @template
end

Instance Method Details

#check_box(name, options = {}) ⇒ Object

Helpers



13
14
15
16
17
# File 'lib/crystal/html/view_helpers/model_helper.rb', line 13

def check_box name, options = {}      
  render_attribute name, options do |fname, value, o|
    form_helper.check_box_tag fname, !!value, o
  end
end

#error_messagesObject



59
60
61
62
# File 'lib/crystal/html/view_helpers/model_helper.rb', line 59

def error_messages
  merrors = errors['base']      
  form_helper.error_messages merrors.to_a unless merrors.blank?
end

#file_field(name, options = {}) ⇒ Object



19
20
21
22
23
# File 'lib/crystal/html/view_helpers/model_helper.rb', line 19

def file_field name, options = {}
  render_attribute name, options do |fname, value, o|
    form_helper.file_field_tag fname, o
  end
end

#hidden_field(name, options = {}) ⇒ Object



25
26
27
28
29
# File 'lib/crystal/html/view_helpers/model_helper.rb', line 25

def hidden_field name, options = {}
  render_attribute name, options do |fname, value, o|
    form_helper.hidden_field_tag fname, value, o
  end
end

#password_field(name, options = {}) ⇒ Object



31
32
33
34
35
# File 'lib/crystal/html/view_helpers/model_helper.rb', line 31

def password_field name, options = {}
  render_attribute name, options do |fname, value, o|
    form_helper.password_field_tag fname, nil, o
  end
end

#radio_button(name, options = {}) ⇒ Object



37
38
39
40
41
# File 'lib/crystal/html/view_helpers/model_helper.rb', line 37

def radio_button name, options = {}
  render_attribute name, options do |fname, value, o|
    form_helper.radio_button_tag fname, !!value, o
  end
end

#submit(value, options = {}) ⇒ Object



43
44
45
# File 'lib/crystal/html/view_helpers/model_helper.rb', line 43

def submit value, options = {}
  form_helper.submit_tag value, options
end

#text_area(name, options = {}) ⇒ Object



53
54
55
56
57
# File 'lib/crystal/html/view_helpers/model_helper.rb', line 53

def text_area name, options = {}
  render_attribute name, options do |fname, value, o|
    form_helper.text_area_tag fname, value, o
  end
end

#text_field(name, options = {}) ⇒ Object



47
48
49
50
51
# File 'lib/crystal/html/view_helpers/model_helper.rb', line 47

def text_field name, options = {}
  render_attribute name, options do |fname, value, o|
    form_helper.text_field_tag fname, value, o
  end
end