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
-
#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, 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.
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
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
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
|
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_name ⇒ Object
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
|
Returns the value of attribute options.
3
4
5
|
# File 'lib/crystal/html/view_helpers/model_helper.rb', line 3
def options
@options
end
|
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
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_messages ⇒ Object
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
|
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
|