TrestleAdmin / trestle-search

Search plugin for the Trestle admin framework
https://trestle.io
GNU Lesser General Public License v3.0
28 stars 11 forks source link

`collection` is nil in custom scope block when using this gem #14

Closed maikokuppe closed 5 years ago

maikokuppe commented 5 years ago

After installing this gem, this does not work anymore (simplified code):

collection do
  Order.all
end

scopes do
  scope :my_orders, -> { collection }
end

The error is

wrong number of arguments (given 0, expected 1)

referencing to the call to collection.

I worked around this by defining collection globally:

collection = Order.all

scopes do
  scope :my_orders, -> { collection }
end

But that's just a workaround.

maikokuppe commented 5 years ago

Oops. Solved it by using the block argument:

collection do
  Order.all
end

scopes do
  scope :my_orders, ->(collection) { collection }
end