class Trestle::Form::Fields::Select::Choices
Allows an array of model instances (or a scope) to be passed to the select field as the list of choices.
Public Class Methods
new(choices)
click to toggle source
# File lib/trestle/form/fields/select.rb, line 34 def initialize(choices) @choices = Array(choices) end
Public Instance Methods
each() { |option_text_and_value(option)| ... }
click to toggle source
# File lib/trestle/form/fields/select.rb, line 38 def each @choices.each do |option| yield option_text_and_value(option) end end
Protected Instance Methods
option_text_and_value(option)
click to toggle source
# File lib/trestle/form/fields/select.rb, line 45 def option_text_and_value(option) if !option.is_a?(String) && option.respond_to?(:first) && option.respond_to?(:last) option elsif option.respond_to?(:id) [Trestle::Display.new(option).to_s, option.id] else [option, option] end end