Skip to content

Commit

Permalink
Change to a named scope with limit
Browse files Browse the repository at this point in the history
  • Loading branch information
mhartl committed Sep 4, 2016
1 parent ba22f6b commit 206d30c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create
private

def get_messages
@messages = Message.all
@messages = Message.for_display
@message = current_user.messages.build
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/message.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Message < ApplicationRecord
belongs_to :user
validates :content, presence: true
default_scope -> { order(:created_at) }
scope :for_display, -> { order(:created_at).limit(50) }
end

0 comments on commit 206d30c

Please sign in to comment.