[RUBY] I tried to sort the data in descending order, ascending order / Rails

When changing the sort of posted data or articles, is the desc in descending order? descending order? I googled it every time, so I summarized it.

board.rb


class Board < ApplicationRecord
  scope :desc, -> { order(created_at: :desc) } #Descending order of creation
  scope :asc, -> { order(id: :asc) } #Ascending order of id Since it is written in asc (ascending order) by default, it is rare to write it explicitly.
end

Recommended Posts

I tried to sort the data in descending order, ascending order / Rails
I tried to organize the session in Rails
How to sort in ascending / descending order with SQLite
[Order method] Set the order of data in Rails
[Rails] I tried to raise the Rails version from 5.0 to 5.2
I tried to organize the cases used in programming
I tried to implement the Euclidean algorithm in Java
Get location information in Rails and sort in ascending order
I tried to explain the method
[Rails] I tried deleting the application
I tried to implement Ajax processing of like function in Rails
I tried to illuminate the Christmas tree in a life game
I tried to implement the image preview function with Rails / jQuery
I tried to understand how the rails method "redirect_to" is defined
I tried to understand how the rails method "link_to" is defined
I tried to summarize the methods used
I tried to introduce CircleCI 2.0 to Rails app
I tried the new era in Java
I tried to make the "Select File" button of the sample application created in the Rails tutorial cool
I tried to implement the Iterator pattern
After learning Progate, I tried to make an SNS application using Rails in the local environment
I tried to summarize the Stream API
I tried the AutoValue library in Intellij
[Rails] I want to send data of different models in a form
I tried to solve the tribonacci sequence problem in Ruby, with recursion.
I tried to make full use of the CPU core in Ruby
[Ruby] I tried to summarize the methods that frequently appear in paiza
[Ruby] I tried to summarize the methods that frequently appear in paiza ②
I tried to implement polymorphic related in Nogizaka.
I tried to implement deep learning in Java
The code I used to connect Rails 3 to PostgreSQL 10
I tried to output multiplication table in Java
I tried to set tomcat to run the Servlet.
I tried to build Micra mackerel in 1 hour!
I tried to develop an application in 2 languages
I tried to create Alexa skill in Java
How to check Rails commands in the terminal
I want to get the value in Ruby
I tried to solve the tribonatch sequence problem in Ruby (time limit 10 minutes)
[Rails / JavaScript / Ajax] I tried to create a like function in two ways.
How to make a unique combination of data in the rails intermediate table
About the case where "Docker" freeter tried to put Docker in the existing Rails application
[Rails] I want to reset everything because the data in the local environment is strange! What to do before that
I was addicted to the NoSuchMethodError in Cloud Endpoints
I tried to express the phone number (landline / mobile phone) with a regular expression in Rails and write validation and test
How to set the display time to Japan time in Rails
I want to embed any TraceId in the log
Tokoro I rewrote in the migration from Wicket 7 to 8
I tried to implement Firebase push notification in Java
I tried to summarize the state transition of docker
I tried to decorate the simple calendar a little
[Rails] I tried playing with the comment send button
05. I tried to stub the source of Spring Boot
# 2 [Note] I tried to calculate multiplication tables in Java.
I want to use a little icon in Rails
I tried to reduce the capacity of Spring Boot
[Rails] How to delete production environment MySQL data after putting it in the development environment
[Rails] I don't know how to use the model ...
I tried to get started with Spring Data JPA
I tried to create a Clova skill in Java
I tried to make a login function in Java