Class: Rad::Html::ModelHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/rad/html/_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.



4
5
6
# File 'lib/rad/html/_helpers/model_helper.rb', line 4

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)



74
75
76
# File 'lib/rad/html/_helpers/model_helper.rb', line 74

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.



2
3
4
# File 'lib/rad/html/_helpers/model_helper.rb', line 2

def form_helper
  @form_helper
end

#modelObject

Returns the value of attribute model.



2
3
4
# File 'lib/rad/html/_helpers/model_helper.rb', line 2

def model
  @model
end

#model_nameObject

Returns the value of attribute model_name.



2
3
4
# File 'lib/rad/html/_helpers/model_helper.rb', line 2

def model_name
  @model_name
end

#optionsObject

Returns the value of attribute options.



2
3
4
# File 'lib/rad/html/_helpers/model_helper.rb', line 2

def options
  @options
end

#templateObject

Returns the value of attribute template.



2
3
4
# File 'lib/rad/html/_helpers/model_helper.rb', line 2

def template
  @template
end

Instance Method Details

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

Helpers



12
13
14
15
16
17
18
# File 'lib/rad/html/_helpers/model_helper.rb', line 12

def check_box name, options = {}
  render_attribute name, options do |fname, value, o|
    html = form_helper.hidden_field_tag(fname, '0') + "\n"
    html += form_helper.check_box_tag fname, !!value, o
    html
  end
end

#error_messagesObject



67
68
69
70
# File 'lib/rad/html/_helpers/model_helper.rb', line 67

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

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



20
21
22
23
24
# File 'lib/rad/html/_helpers/model_helper.rb', line 20

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



26
27
28
29
30
# File 'lib/rad/html/_helpers/model_helper.rb', line 26

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



32
33
34
35
36
# File 'lib/rad/html/_helpers/model_helper.rb', line 32

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, value = 1, options = {}) ⇒ Object



38
39
40
41
42
43
# File 'lib/rad/html/_helpers/model_helper.rb', line 38

def radio_button name, value = 1, options = {}
  render_attribute name, options do |fname, v, o|
    o[:checked] = value == v
    form_helper.radio_button_tag fname, value, o
  end
end

#select(name, values, options = {}) ⇒ Object



61
62
63
64
65
# File 'lib/rad/html/_helpers/model_helper.rb', line 61

def select name, values, options = {}
  render_attribute name, options do |fname, value, o|
    form_helper.select_tag fname, value, values, o
  end
end

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



45
46
47
# File 'lib/rad/html/_helpers/model_helper.rb', line 45

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

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



55
56
57
58
59
# File 'lib/rad/html/_helpers/model_helper.rb', line 55

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



49
50
51
52
53
# File 'lib/rad/html/_helpers/model_helper.rb', line 49

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