Class: Admin::ClientRepresentativesController

Inherits:
ApplicationController
  • Object
show all
Includes:
AdminLayoutHelper, ExtensibleObjectHelper
Defined in:
app/controllers/admin/client_representatives_controller.rb

Instance Method Summary collapse

Methods included from ExtensibleObjectHelper

append_features

Methods included from AdminLayoutHelper

append_features, #controller_url, #define_layout_variables

Methods included from ApplicationHelper

#controller_id, #define_application_layout_variables, #h_money, #money_for_input

Instance Method Details

#merge_conditions(*conditions) ⇒ Object

We override this method b/c at some point in the new active_scaffold code, there was a bug that stopped this from being smart enough to recognize the :uniq on the client_representatives association. in he new_existing action



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/admin/client_representatives_controller.rb', line 35

def merge_conditions(*conditions)    

  if (
    params[:action].to_sym == :new_existing && 
    params.has_key?(:parent_model) && 
    params.has_key?(:eid)
  )
    parent_klass = params[:parent_model].constantize

    # I'm not sure if table_name is the right method to use exactly - but it works here... 
    parent_id = session["as:#{params[:eid]}"][:constraints][parent_klass.table_name.to_sym].to_i if parent_klass

    parent_record = parent_klass.find parent_id if parent_id

    existing_association_ids = parent_record.send('%s_ids' % params[:parent_column].singularize) if parent_record
    
    (existing_association_ids.try(:length) > 0) ? 
      ['`client_representatives`.id NOT IN (?)', existing_association_ids] :
      nil    
  else
    super(*conditions)
  end
end