lib/express_templates/components/forms/select.rb in express_templates-0.4.0 vs lib/express_templates/components/forms/select.rb in express_templates-0.4.1

- old
+ new

@@ -25,19 +25,23 @@ } } # Returns the options which will be supplied to the select_tag helper. def select_options - options_specified = [Array, Hash].include?(@args.second.class) + options_specified = [Array, Hash].include?(@args.second.class) && @args.size > 2 if options_specified options = @args.second else - options = "@#{resource_name}.pluck(:#{field_name}).distinct" + options = "@#{resource_var}.class.distinct(:#{field_name}).pluck(:#{field_name})" end if belongs_to_association && !options_specified - "{{options_from_collection_for_select(#{related_collection}, :id, :name, @#{resource_name}.#{field_name})}}" + if belongs_to_association.polymorphic? + "{{options_for_select([[]])}}" + else + "{{options_from_collection_for_select(#{related_collection}, :id, :#{option_name_method}, @#{resource_name}.#{field_name})}}" + end else if selection = field_options.delete(:selected) "{{options_for_select(#{options}, \"#{selection}\")}}" else "{{options_for_select(#{options}, @#{resource_name}.#{field_name})}}" @@ -46,14 +50,16 @@ end def field_options # If field_otions is omitted the Expander will be # in last or 3rd position and we don't want that - if @args.size > 3 && @args[2].is_a?(Hash) + defaults = {include_blank: true} + field_options = if @args.size > 3 && @args[2].is_a?(Hash) @args[2] else {} end + defaults.merge(field_options) end end end end \ No newline at end of file