Class: Rad::Html::ModelHelper
- Inherits:
-
Object
show all
- Defined in:
- lib/rad/html/_helpers/model_helper.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#check_box(name, options = {}) ⇒ Object
-
#error_messages ⇒ Object
-
#file_field(name, options = {}) ⇒ Object
-
#hidden_field(name, options = {}) ⇒ Object
-
#initialize(template, form_helper, model_name, model, options) ⇒ ModelHelper
constructor
A new instance of ModelHelper.
-
#password_field(name, options = {}) ⇒ Object
-
#radio_button(name, value = 1, options = {}) ⇒ Object
-
#select(name, values, options = {}) ⇒ Object
-
#submit(value, options = {}) ⇒ Object
-
#text_area(name, options = {}) ⇒ Object
-
#text_field(name, options = {}) ⇒ Object
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
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
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
|
Returns the value of attribute model.
2
3
4
|
# File 'lib/rad/html/_helpers/model_helper.rb', line 2
def model
@model
end
|
#model_name ⇒ Object
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
|
Returns the value of attribute options.
2
3
4
|
# File 'lib/rad/html/_helpers/model_helper.rb', line 2
def options
@options
end
|
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
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_messages ⇒ Object
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
|
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
|