refactor: simplify scope limit parameters
- Change `limit:` to `limit =` in the scopes for `latest` and `by_popularity`. - This allows for a default value of 100 to be used if no argument is provided, making the code more user-friendly and consistent. This refactor does not alter the behavior of the existing functionality but streamlines the syntax.
This commit is contained in:
parent
0a6926421f
commit
afcb9c6cd8
@ -12,11 +12,11 @@ class WeatherArt < ApplicationRecord
|
||||
validates :weather_date, presence: true
|
||||
validates :city_id, presence: true
|
||||
|
||||
scope :latest, ->(limit: 100) {
|
||||
scope :latest, ->(limit = 100) {
|
||||
order(created_at: :desc).limit(limit)
|
||||
}
|
||||
|
||||
scope :by_popularity, ->(limit: 100) {
|
||||
scope :by_popularity, ->(limit = 100) {
|
||||
if ActiveRecord::Base.connection.adapter_name.downcase == "sqlite"
|
||||
joins("LEFT JOIN ahoy_events ON json_extract(ahoy_events.properties, '$.weather_art_id') = weather_arts.id
|
||||
AND json_extract(ahoy_events.properties, '$.event_type') = 'weather_art_view'")
|
||||
|
Loading…
Reference in New Issue
Block a user