0
私のレールアプリでアクションストリームを作成しようとしています。ここでは、ユーザーが受け取ったお気に入りのリストと、ユーザーの友人が書き込んだストーリーのリストを生成するために使用するヘルパーメソッドを示します。レールでユーザアクションストリームを作成する
後で、これらを1つの配列にまとめてビューに表示するだけです。しかし、私は最終的な配列を日付順にソートしたいのですが、以前のメソッドで.map
を使用した場合、そこに日付オブジェクトを取得して並べ替える方法がわかりません。
def get_stream(current_user)
stories = get_friends_stories(current_user)
likes = get_likes(current_user)
stream = [stories, likes]
stream.flatten
end
def get_likes(user)
stories = get_stories(user)
likes = Like.find_all_by_story_id(stories)
hash = likes.map {|like| "#{like.user.display_name} liked your story #{like.story.title}" }
end
def get_friends_stories(user)
friends = get_friends(user)
friend_ids = friends.map {|f| f.friend_id }
stories = Story.find_all_by_user_id(friend_ids)
hash = stories.map {|story| "#{story.user.display_name} wrote a story called #{story.title}" }
end