Feature request: has_scope for other models in a controller
mzemel opened this issue · 1 comments
mzemel commented
If I have a model
class Bar
belongs_to Foo
scope :active, ->{ where(status: "active") }
end
and another resource's controller (FooController
), it would be really cool if I could somehow add a flag to has_scope
to tell the controller that the scope belongs on an ActiveRecord Relation of Bar
objects:
class FooController < ApplicationController
has_scope :active # add something here
def show
apply_scopes(Foo.find(params[:id]).bar).all
end
end
If this makes sense, maybe it's something I could try putting a PR together for. It doesn't look possible from the source code (couldn't determine naming deductions, but I'm assuming you get the model from the naming of the controller) but if it is possible and you could tell me how to do that, I'd love to use this gem.
mzemel commented
Never mind; the target is whatever's passed to #apply_scopes
, not inferred from the controller name; I was using it wrong.