Sha256: 59e9e8a060fe8c412e7cddcdc6ec4df7f369c579b0ef1eb1bbd4bc132f0b58b1

Contents?: true

Size: 1.21 KB

Versions: 15

Compression:

Stored size: 1.21 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  nil
  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.association(attribute.to_sym).reflection.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

15 entries across 15 versions & 1 rubygems

Version Path
inline_forms-1.4.6 lib/app/helpers/form_elements/dropdown.rb
inline_forms-1.4.5 lib/app/helpers/form_elements/dropdown.rb
inline_forms-1.4.4 lib/app/helpers/form_elements/dropdown.rb
inline_forms-1.4.3 lib/app/helpers/form_elements/dropdown.rb
inline_forms-1.4.2 lib/app/helpers/form_elements/dropdown.rb
inline_forms-1.4.1 lib/app/helpers/form_elements/dropdown.rb
inline_forms-1.4.0 lib/app/helpers/form_elements/dropdown.rb
inline_forms-1.3.49 lib/app/helpers/form_elements/dropdown.rb
inline_forms-1.3.48 lib/app/helpers/form_elements/dropdown.rb
inline_forms-1.3.47 lib/app/helpers/form_elements/dropdown.rb
inline_forms-1.3.45 lib/app/helpers/form_elements/dropdown.rb
inline_forms-1.3.44 lib/app/helpers/form_elements/dropdown.rb
inline_forms-1.3.43 lib/app/helpers/form_elements/dropdown.rb
inline_forms-1.3.42 lib/app/helpers/form_elements/dropdown.rb
inline_forms-1.3.41 lib/app/helpers/form_elements/dropdown.rb