Sha256: 6c0d4b07572d92d07cf6fabbd2c796e96d3bcb075793ab15bda320e0f8b0fdc5
Contents?: true
Size: 1.84 KB
Versions: 17
Compression:
Stored size: 1.84 KB
Contents
# -*- encoding : utf-8 -*- InlineForms::SPECIAL_COLUMN_TYPES[:dropdown]=:belongs_to # dropdown def dropdown_show(object, attribute) attr = object.send attribute presentation = "_presentation" presentation = "_dropdown_presentation" if attr.respond_to? "_dropdown_presentation" attribute_value = object.send(attribute).send(presentation) rescue "<i class='fi-plus'></i>".html_safe link_to_inline_edit object, attribute, attribute_value end def dropdown_edit(object, attribute) object.send('build_' + attribute.to_s) unless object.send(attribute) # we really need this! attr = object.send attribute presentation = "_presentation" presentation = "_dropdown_presentation" if attr.respond_to? "_dropdown_presentation" klass = object.send(attribute).class if cancan_enabled? values = klass.accessible_by(current_ability) else values = klass.all end options_disabled = nil if klass.method_defined? :disabled_for_dropdown? options_disabled = values.map{|v| v.id if v.disabled_for_dropdown?}.compact end values.sort_by! {|v|v.send presentation} # the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form! collection_select( ('_' + object.class.to_s.underscore).to_sym, attribute.to_s.foreign_key.to_sym, values, 'id', presentation, selected: (object.send(attribute).id rescue nil), disabled: options_disabled, ) end def dropdown_update(object, attribute) foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.to_s.foreign_key.to_sym object[foreign_key] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_s.foreign_key.to_sym] end
Version data entries
17 entries across 17 versions & 1 rubygems