Module: Rapid::Web::SelectHelpers
- Defined in:
- lib/rapid/web/select_helpers.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#options_for_select(option_items, selected_values = []) ⇒ Object
Returns the options tags for a select based on the given option items.
-
#time_zone_options_for_select(options = {}) ⇒ Object
File actionpack/lib/action_view/helpers/form_options_helper.rb, line 504.
- #time_zone_select(name, options = {}) ⇒ Object
Class Method Details
.registered(app) ⇒ Object
6 7 8 9 |
# File 'lib/rapid/web/select_helpers.rb', line 6 def self.registered(app) app.set :default_builder, 'Rapid::Web::SettingsFormBuilder' app.helpers self end |
Instance Method Details
#options_for_select(option_items, selected_values = []) ⇒ Object
Returns the options tags for a select based on the given option items
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rapid/web/select_helpers.rb', line 12 def (option_items, selected_values=[]) return '' if option_items.blank? selected_values = [selected_values].compact unless selected_values.is_a?(Array) items = option_items.collect { |, value| value ||= selected = selected_values.find {|v| v.to_s =~ /^(#{Regexp.escape(value)}|#{Regexp.escape()})$/} content_tag(:option, , :value => value, :selected => !!selected) } items.join("\n") end |
#time_zone_options_for_select(options = {}) ⇒ Object
File actionpack/lib/action_view/helpers/form_options_helper.rb, line 504
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rapid/web/select_helpers.rb', line 34 def ( = {}) selected = .delete(:selected) priority_zones = .delete(:priority) model = .delete(:model) || ::ActiveSupport::TimeZone include_blank = .delete(:include_blank) = "" += %(<option value=""></option>) if include_blank zones = model.all convert_zones = lambda { |list| list.map { |z| [ z.to_s, z.name ] } } if priority_zones if priority_zones.is_a?(Regexp) priority_zones = model.all.find_all {|z| z =~ priority_zones} end += (convert_zones[priority_zones], selected) += "<option value=\"\" disabled=\"disabled\">-------------</option>\n" zones = zones.reject { |z| priority_zones.include?( z ) } end += (convert_zones[zones], selected) .html_safe end |
#time_zone_select(name, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/rapid/web/select_helpers.rb', line 23 def time_zone_select name, = {} .reverse_merge!(:name => name) collection, fields = .delete(:collection), .delete(:fields) [:options] = (collection, fields) if collection # options[:options].unshift('') if options.delete(:include_blank) = () .merge!(:name => "#{[:name]}[]") if [:multiple] content_tag(:select, , ) end |