Previously I've been overriding the scope in the controller using @scope. This seems undocumented, but it works.
I see that I can override the scope like this:
grid:
class ProjectsGrid
include Datagrid
scope { Project.includes(:category) }
end
controller:
grid = ProjectsGrid.new(grid_params) do |scope|
scope.where(:owner_id => current_user.id)
end
Unfortunately it seems that the scope isn't then passed to filters for some reason:
filter(:payment_submethod, :enum, select: :available_payment_submethods, multiple: true, dummy: true) do |values, scope|
scope.merge OnlineStoreOrder.where(payment_submethod: values)
end
The last example is from my app. When passing in @scope from the controller it arrives at that block, but if I do it via the do |scope| block style above I get scope being undefined method 'merge' for nil:NilClass.
Previously I've been overriding the scope in the controller using
@scope
. This seems undocumented, but it works.I see that I can override the scope like this:
grid:
controller:
Unfortunately it seems that the scope isn't then passed to filters for some reason:
The last example is from my app. When passing in @scope from the controller it arrives at that block, but if I do it via the
do |scope|
block style above I get scope beingundefined method 'merge' for nil:NilClass
.Do you have any pointers on this usage?