Module: CommonLib::ActionViewExtension::FormBuilder
- Defined in:
- lib/common_lib/action_view_extension/form_builder.rb
Instance Method Summary collapse
- #adna_select(method, options = {}, html_options = {}) ⇒ Object
- #date_text_field(method, options = {}) ⇒ Object
- #datetime_text_field(method, options = {}) ⇒ Object
- #error_messages ⇒ Object
- #hour_select(method, options = {}, html_options = {}) ⇒ Object
- #meridiem_select(method, options = {}, html_options = {}) ⇒ Object
- #minute_select(method, options = {}, html_options = {}) ⇒ Object
- #padk_select(method, options = {}, html_options = {}) ⇒ Object
- #pos_neg_select(method, options = {}, html_options = {}) ⇒ Object
- #sex_select(method, options = {}, html_options = {}) ⇒ Object (also: #gender_select)
- #wrapped_check_box(*args, &block) ⇒ Object
- #yndk_select(method, options = {}, html_options = {}) ⇒ Object
- #ynodk_select(method, options = {}, html_options = {}) ⇒ Object
- #ynordk_select(method, options = {}, html_options = {}) ⇒ Object
- #ynrdk_select(method, options = {}, html_options = {}) ⇒ Object
Instance Method Details
#adna_select(method, options = {}, html_options = {}) ⇒ Object
103 104 105 106 |
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 103 def adna_select(method,={},={}) @template.select(object_name, method, ADNA., {:include_blank => true}.merge(()), ) end |
#date_text_field(method, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 43 def date_text_field(method, = {}) format = .delete(:format) || '%m/%d/%Y' tmp_value = if [:value].blank? #and !options[:object].nil? # object = options[:object] tmp = self.object.send("#{method}") || self.object.send("#{method}_before_type_cast") else [:value] end begin [:value] = tmp_value.to_date.try(:strftime,format) rescue NoMethodError, ArgumentError [:value] = tmp_value end .update(:class => [[:class],'datepicker'].compact.join(' ')) @template.text_field( object_name, method, ) end |
#datetime_text_field(method, options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 61 def datetime_text_field(method, = {}) format = .delete(:format) || '%m/%d/%Y %H:%M' tmp_value = if [:value].blank? tmp = self.object.send("#{method}") || self.object.send("#{method}_before_type_cast") else [:value] end begin [:value] = tmp_value.to_datetime.try(:strftime,format) rescue NoMethodError, ArgumentError [:value] = tmp_value end .update(:class => [[:class],'datetimepicker'].compact.join(' ')) @template.text_field( object_name, method, ) end |
#error_messages ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 3 def if self.object.errors.count > 0 s = '<div id="errorExplanation" class="errorExplanation">' s << "<h2>#{self.object.errors.count} #{"error".pluralize(self.object.errors.count)} prohibited this #{self.object.class} from being saved:</h2>" s << '<p>There were problems with the following fields:</p>' s << '<ul>' self.object.errors..each do |msg| s << "<li>#{msg}</li>" end s << '</ul></div>' s.html_safe end end |
#hour_select(method, options = {}, html_options = {}) ⇒ Object
17 18 19 20 21 |
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 17 def hour_select(method,={},={}) @template.select(object_name, method, (1..12), {:include_blank => 'Hour'}.merge(), ) end |
#meridiem_select(method, options = {}, html_options = {}) ⇒ Object
30 31 32 33 34 |
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 30 def meridiem_select(method,={},={}) @template.select(object_name, method, ['AM','PM'], {:include_blank => 'Meridiem'}.merge(), ) end |
#minute_select(method, options = {}, html_options = {}) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 23 def minute_select(method,={},={}) minutes = (0..59).to_a.collect{|m|[sprintf("%02d",m),m]} @template.select(object_name, method, minutes, {:include_blank => 'Minute'}.merge(), ) end |
#padk_select(method, options = {}, html_options = {}) ⇒ Object
98 99 100 101 |
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 98 def padk_select(method,={},={}) @template.select(object_name, method, PADK., {:include_blank => true}.merge(()), ) end |
#pos_neg_select(method, options = {}, html_options = {}) ⇒ Object
108 109 110 111 |
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 108 def pos_neg_select(method, ={}, ={}) @template.select(object_name, method, POSNEG., {:include_blank => true}.merge(()), ) end |
#sex_select(method, options = {}, html_options = {}) ⇒ Object Also known as: gender_select
36 37 38 39 40 |
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 36 def sex_select(method,={},={}) @template.select(object_name, method, [['-select-',''],['male','M'],['female','F'],["don't know",'DK']], , ) end |
#wrapped_check_box(*args, &block) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 113 def wrapped_check_box(*args,&block) method = args[0] content = @template.field_wrapper(method,:class => 'check_box') do = args.detect{|i| i.is_a?(Hash) } label_text = .delete(:label_text) unless .nil? post_text = .delete(:post_text) unless .nil? # INVERTED ORDER SO NOT INCLUDED BELOW s = check_box(*args,&block) << self.label( method, label_text ) s << (( block_given? )? @template.capture(&block) : '') s << (( post_text.blank? ) ? '' : "<span>#{post_text}</span>".html_safe ) end content.html_safe end |
#yndk_select(method, options = {}, html_options = {}) ⇒ Object
78 79 80 81 |
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 78 def yndk_select(method,={},={}) @template.select(object_name, method, YNDK., {:include_blank => true}.merge(()), ) end |
#ynodk_select(method, options = {}, html_options = {}) ⇒ Object
88 89 90 91 |
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 88 def ynodk_select(method,={},={}) @template.select(object_name, method, YNODK., {:include_blank => true}.merge(()), ) end |