1

I am new to Rails 6 and I am getting above error. Please check the below code and help me to get out of this. Thanks!

has_many :coaches, ->{where('max_unit > 0 and active = 1').order('trim(full_name)')}, ->{select((Account.column_names - ['photo_file']).map { |column_name| "`accounts`.`#{column_name}`"})}, :through => :qualifications

backtrace: ArgumentError (wrong number of arguments (given 3, expected 1..2)):

app/models/language.rb:9:in <class:Language>' app/models/language.rb:1:in ' app/models/account.rb:142:in manage_substitutions' app/controllers/extranet/homes_controller.rb:11:in index'

seshadri_c
  • 6,906
  • 2
  • 10
  • 24

1 Answers1

1

You are giving two lambdas as separate arguments here.

The first is

->{where('max_unit > 0 and active = 1').order('trim(full_name)')}`

The second is

->{select((Account.column_names - ['photo_file']).map { |column_name| "`accounts`.`#{column_name}`"})}

This is invalid. You should combine the two lambdas into one:

-> {
  where('max_unit > 0 and active = 1').
  order('trim(full_name)').
  select((Account.column_names - ['photo_file']).map { |column_name| "`accounts`.`#{column_name}`"})
}

You should also check this out, it's a potentially cleaner way to do this: https://stackoverflow.com/a/33939206/2981429

max pleaner
  • 26,189
  • 9
  • 66
  • 118