I have the following scope defined in my model:
scope :answers_in, -> (answers = nil) do
return unless answers.present?
where(answer_1: answers).or(where(answer_2: answers))
end
The answers should by an array. However, when I make a call passing an array, receive an argument error:
AnswerConnection.answers_in([1, 2])
ArgumentError: wrong number of arguments (given 2, expected 0..1)
from /vagrant/farma_alg_reborn/app/models/answer_connection.rb:7:in `block in <class:AnswerConnection>'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.1/lib/active_record/scoping/named.rb:159:in `instance_exec'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.1/lib/active_record/scoping/named.rb:159:in `block (2 levels) in scope'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.1/lib/active_record/relation.rb:351:in `scoping'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.1/lib/active_record/scoping/named.rb:159:in `block in scope'
from (irb):2
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/commands/console.rb:65:in `start'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/commands/console_helper.rb:9:in `start'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/commands.rb:18:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `block in require'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
from /vagrant/farma_alg_reborn/bin/rails:9:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `load'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `block in load'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `load'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/commands/rails.rb:6:in `call'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/command_wrapper.rb:38:in `call'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:191:in `block in serve'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:161:in `fork'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:161:in `serve'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:131:in `block in run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:125:in `loop'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:125:in `run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application/boot.rb:19:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
Is this a bug, Rails scopes doesn't work with arrays or I'm doing something wrong?