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)endand 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])endwith these new methods in the model:def self.ordered  order(deadline DESC)enddef self.paginated(page: 1)  paginate(page: page, per_page: self.pagination_per_page)enddef self.assigned_default(page: 1)  uncompleted.includes(executor: :profile).ordered.paginated(page: page)endShould I do something differently or is this okay?
Extracting queries from controller to model
ruby;ruby on rails;controller;active record
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 -> { order(deadline: 'DESC') }scope :paginated -> (page: 1) { paginate(page: page, per_page: pagination_per_page) }scope :assigned_default -> (page: 1) { uncompleted.includes(executor: :profile).ordered.paginated(page: page) }