Мне нужно получить все текущие статусы current_user.friends, а затем отсортировать их по created_at.
class User < ActiveRecord::Base
has_many :statuses
end
class Status < ActiveRecord::Base
belongs_to :user
end
И в контроллере:
def index
@statuses = []
current_user.friends.map{ |friend| friend.statuses.each { |status| @statuses << status } }
current_user.statuses.each { |status| @statuses << status }
@statuses.sort! { |a,b| b.created_at <=> a.created_at }
end
current_user.friends
возвращает массив объектов User
friend.statuses
возвращает массив объектов Status
Ошибка:
comparison of Status with Status failed
app/controllers/welcome_controller.rb:10:in `sort!'
app/controllers/welcome_controller.rb:10:in `index'