Sha256: c244c8b09086a2a162a954a6e322a3a2c835ff72dfcdc8ac691c73f173e3eec7

Contents?: true

Size: 1.38 KB

Versions: 47

Compression:

Stored size: 1.38 KB

Contents

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

# dropdown
def chicas_dropdown_with_family_members_show(object, attribute)
  attribute_value = object.send(attribute)._dropdown_presentation rescue  "<i class='fi-plus'></i>".html_safe
  link_to_inline_edit object, attribute, attribute_value
end

def chicas_dropdown_with_family_members_edit(object, attribute)
  o = object.send(attribute) # the client
  values = o.family.clients
  values.sort_by! &:_dropdown_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', '_dropdown_presentation', :selected => object.send(attribute).id)
end

def chicas_dropdown_with_family_members_update(object, attribute)
  foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.to_s.foreign_key.to_sym
  old_path = File.dirname(object.image.path)
  object[foreign_key] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_s.foreign_key.to_sym]
  if object.save
   # move to new location
   new_path = File.join(Rails.root, "public/uploads/client/photo/#{object.client_id}")
   system "mkdir -vp #{new_path}"
   system "mv -v #{old_path} #{new_path}"
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
inline_forms-3.2.11 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.2.10 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.2.9 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.2.8 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.2.7 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.2.6 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.2.5 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.2.4 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.2.3 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.2.2 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.2.1 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.2.0 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.1.9 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.1.8 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.1.7 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.1.6 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.1.5 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.1.4 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.1.3 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb
inline_forms-3.1.2 lib/app/helpers/form_elements/chicas_dropdown_with_family_members.rb