Skip to content

Custom Scopes with groupings? #653

@JFimex

Description

@JFimex

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions