Sha256: 60818aec44292ffefd0cdbcf26930150ac0cfd5b79e804bca5ac8a489c1d1c99

Contents?: true

Size: 1.25 KB

Versions: 52

Compression:

Stored size: 1.25 KB

Contents

# -*- encoding : utf-8 -*-
InlineForms::SPECIAL_COLUMN_TYPES[:dropdown]=:belongs_to

# dropdown
def dropdown_show(object, attribute)
  attribute_value = object.send(attribute)._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)
  o = object.send(attribute).class.name.constantize
  if cancan_enabled?
    values = o.accessible_by(current_ability).order(o.order_by_clause)
  else
    values = o.order(o.order_by_clause)
  end
  values.each do |v|
    v.name = v._presentation
  end
  values.sort_by! &:name
  # 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', 'name', :selected => object.send(attribute).id)
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

52 entries across 52 versions & 1 rubygems

Version Path
inline_forms-3.0.34 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.32 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.31 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.30 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.29 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.28 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.27 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.26 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.25 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.24 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.23 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.22 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.21 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.20 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.19 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.18 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.17 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.16 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.15 lib/app/helpers/form_elements/dropdown.rb
inline_forms-3.0.14 lib/app/helpers/form_elements/dropdown.rb