|
2 | 2 |
|
3 | 3 | module RecurringSelectHelper
|
4 | 4 | module FormHelper
|
5 |
| - if Rails::VERSION::MAJOR >= 4 |
6 |
| - def select_recurring(object, method, default_schedules = nil, options = {}, html_options = {}) |
7 |
| - RecurringSelectTag.new(object, method, self, default_schedules, options, html_options).render |
8 |
| - end |
9 |
| - elsif Rails::VERSION::MAJOR == 3 |
10 |
| - def select_recurring(object, method, default_schedules = nil, options = {}, html_options = {}) |
11 |
| - InstanceTag.new(object, method, self, options.delete(:object)).to_recurring_select_tag(default_schedules, options, html_options) |
12 |
| - end |
| 5 | + def select_recurring(object, method, default_schedules = nil, options = {}, html_options = {}) |
| 6 | + RecurringSelectTag.new(object, method, self, default_schedules, options, html_options).render |
13 | 7 | end
|
14 | 8 | end
|
15 | 9 |
|
@@ -96,51 +90,24 @@ def recurring_select_html_options(html_options)
|
96 | 90 | end
|
97 | 91 | end
|
98 | 92 |
|
99 |
| - if Rails::VERSION::STRING.to_f >= 4.0 |
100 |
| - # === Rails 4 |
101 |
| - class RecurringSelectTag < ActionView::Helpers::Tags::Base |
102 |
| - include RecurringSelectHelper::FormOptionsHelper |
103 |
| - include SelectHTMLOptions |
104 |
| - |
105 |
| - def initialize(object, method, template_object, default_schedules = nil, options = {}, html_options = {}) |
106 |
| - @default_schedules = default_schedules |
107 |
| - @choices = @choices.to_a if @choices.is_a?(Range) |
108 |
| - @method_name = method.to_s |
109 |
| - @object_name = object.to_s |
110 |
| - @html_options = recurring_select_html_options(html_options) |
111 |
| - add_default_name_and_id(@html_options) |
112 |
| - |
113 |
| - super(object, method, template_object, options) |
114 |
| - end |
| 93 | + class RecurringSelectTag < ActionView::Helpers::Tags::Base |
| 94 | + include RecurringSelectHelper::FormOptionsHelper |
| 95 | + include SelectHTMLOptions |
115 | 96 |
|
116 |
| - def render |
117 |
| - if Rails::VERSION::STRING >= '5.2' |
118 |
| - option_tags = add_options(recurring_options_for_select(value, @default_schedules, @options), @options, value) |
119 |
| - else |
120 |
| - option_tags = add_options(recurring_options_for_select(value(object), @default_schedules, @options), @options, value(object)) |
121 |
| - end |
122 |
| - select_content_tag(option_tags, @options, @html_options) |
123 |
| - end |
| 97 | + def initialize(object, method, template_object, default_schedules = nil, options = {}, html_options = {}) |
| 98 | + @default_schedules = default_schedules |
| 99 | + @choices = @choices.to_a if @choices.is_a?(Range) |
| 100 | + @method_name = method.to_s |
| 101 | + @object_name = object.to_s |
| 102 | + @html_options = recurring_select_html_options(html_options) |
| 103 | + add_default_name_and_id(@html_options) |
| 104 | + |
| 105 | + super(object, method, template_object, options) |
124 | 106 | end
|
125 | 107 |
|
126 |
| - else |
127 |
| - # === Rails 3 |
128 |
| - class InstanceTag < ActionView::Helpers::InstanceTag |
129 |
| - include RecurringSelectHelper::FormOptionsHelper |
130 |
| - include SelectHTMLOptions |
131 |
| - |
132 |
| - def to_recurring_select_tag(default_schedules, options, html_options) |
133 |
| - html_options = recurring_select_html_options(html_options) |
134 |
| - add_default_name_and_id(html_options) |
135 |
| - value = value(object) |
136 |
| - options = add_options( |
137 |
| - recurring_options_for_select(value, default_schedules, options), |
138 |
| - options, value |
139 |
| - ) |
140 |
| - content_tag("select", options, html_options) |
141 |
| - end |
| 108 | + def render |
| 109 | + option_tags = add_options(recurring_options_for_select(value, @default_schedules, @options), @options, value) |
| 110 | + select_content_tag(option_tags, @options, @html_options) |
142 | 111 | end
|
143 | 112 | end
|
144 |
| - |
145 |
| - |
146 | 113 | end
|
0 commit comments