Skip to content
Permalink
4f2f61558d
Go to file
 
 
Cannot retrieve contributors at this time
16 lines (14 sloc) 563 Bytes
class Micropost < ActiveRecord::Base
before_save { }
belongs_to :user
default_scope -> { order('created_at DESC') }
validates :content, presence: true, length: { maximum: 140 }
validates :user_id, presence: true
# Returns microposts from the users being followed by the given user.
def self.from_users_followed_by(user)
followed_user_ids = "SELECT followed_id FROM relationships
WHERE follower_id = :user_id"
where("user_id IN (#{followed_user_ids}) OR user_id = :user_id",
user_id: user.id)
end
end
You can’t perform that action at this time.