Skip to content

Commit 57c0d0f

Browse files
committed
refactor: ニュース取得ロジックをモデルに移動
1 parent 18fa06c commit 57c0d0f

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

app/controllers/home_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ def show
33
@dojo_count = Dojo.active_dojos_count
44
@regions_and_dojos = Dojo.group_by_region_on_active
55
@prefectures_and_dojos = Dojo.group_by_prefecture_on_active
6-
@news_items = News.all.order(published_at: :desc).limit(7)
6+
@news_items = News.recent.limit(7)
77
end
88
end

app/models/news.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
class News < ApplicationRecord
2+
scope :recent, -> { order(published_at: :desc) }
23
end

0 commit comments

Comments
 (0)