diff --git a/app/models/user.rb b/app/models/user.rb index 69305a6e..4795c9ba 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -43,6 +43,11 @@ class User < ActiveRecord::Base end end + # @return [Array] the users' timeline + def timeline + Answer.where("user_id in (?) OR user_id = ?", friend_ids, id).order(:created_at).reverse_order + end + # follows an user. def follow(target_user) active_relationships.create(target: target_user) @@ -52,6 +57,7 @@ class User < ActiveRecord::Base target_user.increment! :follower_count end + # unfollows an user def unfollow(target_user) active_relationships.find_by(target: target_user).destroy diff --git a/app/views/static/index.html.haml b/app/views/static/index.html.haml index 11a442ad..64516ae7 100644 --- a/app/views/static/index.html.haml +++ b/app/views/static/index.html.haml @@ -1,9 +1,10 @@ - if user_signed_in? .container - %h1 Static#index + %h1 Timeline = render 'layouts/messages' - %p Find me in app/views/static/index.html.haml + - current_user.timeline.each do |answer| + = render 'shared/answerbox', a: answer = render "shared/links" - else .jumbotron