DRY up help using #method


  target_model_class = Object.const_get(target) # target == 'business_areas' - passed as argument   source_model_class = Object.const_get(source) # source == 'business_applications' - passed as argument

  attributes = params[...] # values from a form in a view   source_instance = source_model_class.find(...) # id from view   target_instance = target_model_class.create! attributes   source_instance.method(target) << target_instance unless source_instance.nil?   source_instance.save

But gets the following error complaining << method does not exist:

  undefined method `<<' for #<Method: BusinessApplication#business_areas>

You don't need to use #method method : you don't want to manipulate a Method object but you just want to send a message whose name is an association.

You should look at : source_instance.send(target)

   -- Jean-François.