Extracting queries from controller to model I had a complex query in the controller like:

def outgoing_tasks
  @tasks = current_user.
           assigned_tasks.
           uncompleted.
           includes(executor: :profile).
           order("deadline DESC").
           paginate(page: params[:page], per_page: Task.pagination_per_page)
end


and since I have some other collections in that controller I refactored to this:

def outgoing_tasks
  @tasks = current_user.assigned_tasks.assigned_default(page: params[:page])
end


with these new methods in the model:

def self.ordered
  order("deadline DESC")
end

def self.paginated(page: 1)
  paginate(page: page, per_page: self.pagination_per_page)
end

def self.assigned_default(page: 1)
  uncompleted.includes(executor: :profile).ordered.paginated(page: page)
end


Should I do something differently or is this okay?
This is a good place to use scopes. http://edgeguides.rubyonrails.org/active_record_querying.html#scopes Scopes are just syntactic sugar for class methods that return relations. In this way they can always be chain-able.

scope :ordered -&gt; { order(deadline: 'DESC') }
scope :paginated -&gt; (page: 1) { paginate(page: page, per_page: pagination_per_page) }
scope :assigned_default -&gt; (page: 1) { uncompleted.includes(executor: :profile).ordered.paginated(page: page) }