ransack icon indicating copy to clipboard operation
ransack copied to clipboard

Custom Scopes with groupings?

Open JFimex opened this issue 8 years ago • 3 comments

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?

JFimex avatar Mar 17 '16 11:03 JFimex

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.

avit avatar Mar 17 '16 19:03 avit

+1

brunomeira avatar Dec 19 '16 20:12 brunomeira

Any news about this issue?

pedrofurtado avatar Dec 12 '19 16:12 pedrofurtado