Default sort order in index views - StanfordBioinformatics/pulsar_lims GitHub Wiki
This is established in the Pundit application policy in app/policies/application_policy.rb
. Basically, all index views make a call to the policy_scope
helper, i.e. below is the index action of the Donors controller:
def index @records = policy_scope(Donor).page params[:page] end
If you read the Pundit documentation, you'll discover that this helper is a shortcut for calling the Scope#resolve
method, that lives in whichever policy class is registered with the model. In Pulsar LIMS, all models are registered with the default ApplicationPolicy
class that the Pundit generator gives you, as all models set the following class method:
def self.policy_class ApplicationPolicy end
Thus, setting the default sort order in ApplicationPolicy::Scope#resolve
is the simplest and most straightforward way, and doesn't require setting it explicitly in each index action.