ransack
ransack copied to clipboard
Custom Scopes with groupings?
Suppose I have the model:
class Model < ActiveRecord::Base
scope :test_scope, -> { where(foo: "foo", bar: "bar")}
def self.ransackable_scopes(a = nil)
%i( test_scope )
end
end
the controller:
def index
@q = Model.ransack(params[:p])
@models = @q.result
if @q.groupings.blank?
@q.build_grouping
end
end
the view:
<%=search_form_for @q do |f|%>
<%=f.grouping_fields @q.groupings[0] do |g|%>
<%=g.check_box :test_scope%>
<%end%>
<%end%>
this throws:
undefined method `test_scope' for Grouping <>:Ransack::Nodes::Grouping
Is there a correct way to use groupings with scopes?
Unfortunately scopes are only attached to the top level search right now. It would be nice to get it moved into the nested context, but that's going to take some work.
+1
Any news about this issue?