User.order(email: :desc)
Page.order("category_id ASC")
# SELECT "pages".* FROM "pages" ORDER BY category_id ASC
User.order(:name, email: :desc)
# SELECT "users".* FROM "users" ORDER BY "users"."name" ASC, "users"."email" DESC
# rails >=7
result = user.user_books.in_order_of(:status, %w[to_read currently_reading read])
=> #<ActiveRecord::Relation [#<UserBook id: 3, user_id: 1, status: "to_read">, #<UserBook id: 4, user_id: 1, status: "to_read">, #<UserBook id: 5, user_id: 1, status: "currently_reading">, #<UserBook id: 6, user_id: 1, status: "read">]>
Code Example |
---|
Ruby :: ruby run bash command |
Ruby :: rails date format dd/mm/yyyy |
Ruby :: list ruby versions |
Ruby :: method delete rails not working |
Ruby :: ruby square root |
Ruby :: ruby timestamp |
Ruby :: rails activerecord to hash |
Ruby :: ruby generate uuid |
Ruby :: ruby array prepend vs unshift |
Ruby :: ruby loop each with index |
Ruby :: ruby class |
Ruby :: link to do rails |
Ruby :: ruby compiler |
Ruby :: how to call ruby private methods |
Ruby :: rails devise valid_password |
Ruby :: ruby array shift |
Ruby :: random number rails |
Ruby :: run ruby script |
Ruby :: ruby if else |
Ruby :: ruby string format |
Ruby :: map each with index |
Ruby :: what is touch in rails |
Ruby :: rails interrupt if tooo long |
Ruby :: rotate array by k times in rails |
Ruby :: set db environment to development |
Ruby :: transfer encoding chunked ruby |
Ruby :: how to use custom switch in rails |
R :: r ggplot regression line |
R :: how to select all the records above a specific datetime in r |
R :: r rename columns |