Ruby on Rails Wednesday, March 2, 2016

I've been trying to combine my own post with the users that I follow in
chronological order DESC. Can you help me build the proper query method
for it?


What I currently have is the code below

def feed
following_ids = current_user.following_users.map(&:id)
@following_activities =
Post.where(user_id:following_ids).order("created_at
desc").paginate(page:params[:page])
@following_activities << current_user.posts.order('created_at
desc').all
@following_activities = @following_activities.flatten.sort_by
{|post| post.created_at }
end

Feed.html.erb
<% if @following_activities.any? %>
<% @following_activities.each do |user| %>
<%= link_to(image_tag(user.avatar.url(:thumb), style:
'text-decoration: none;', class: 'round-image-50-trendy-warrior'),
user_path(user)) %>
<%= user.post.username %>
<%= user.post.body %>
<%= image_tag(user.post.photo.url(:medium), style: '') %>
<% end %>
<% else %>
<h1>No new posts</h1>
<% end %>

The approach that I'm using is not causing any server errors. But, I'm
not seeing the post that I've already created, they aren't being loaded.

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5317cf6d26c8523f7496dc2931f4d1a7%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment