Ruby on Rails: Push Posts in to a hash and then show them -


i'm creating twitter-copy , right i'm trying posts users follow , show them on home page. i've done in php before, i'm new @ ror might trying wrong way.

a user has many subscriptions , subscription belongs user

a user has many posts , post belongs user

this i've got far:

session_controller.rb

def get_posts   @sub = @current_user.subscriptions.first   post.where("user_id = ?", @sub.following_id).find_each |tweet|     render partial: 'shared/tweet', locals: {tweet: tweet}   end end 

i know .first gets first subscription, wanted try out.

home.html.erb

<table>     <tr>         <th>username</th>         <th>tweet</th>     </tr>     <%= yield %> </table> 

_tweet.html.erb

<div class="tweet">     <td>username here somehow</td>     <td><%= tweet.content %></td> </div> 

but right nothing coming in table.. so, doing wrong? (am doing right @ all?)

try this:

session_controller.rb

def get_posts   @sub = @current_user.subscriptions.first   @tweets = post.where("user_id = ?", @sub.following_id) end 

home.html.erb

<table>   <thead>     <tr>         <th>username</th>         <th>tweet</th>     </tr>   </thead>   <tbody>    <% @tweets.each |tweet| %>      <%= render 'shared/tweet', tweet: tweet %>    <% end %>   </tbody> </table> 

_tweet.html.erb

<tr class="tweet">     <td><%= tweet.user.name %></td> # not sure     <td><%= tweet.content %></td> </tr> 

edit:

to tweets subscritions:

following_ids = @current_user.subscriptions.map(&:following_id) @tweets = post.where(user_id: following_ids) 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -