Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3: rails newbie confused about routes/controllers
    text
    copied!<p>I've created a small twitter clone app where users make posts, follow other users, and have a feed of all the posts by the user's they follow. I've added a choice of categories for the posts to fall into, "thriller" "western" "horror" and so on. </p> <p>When a user is logged in, the root web address is their dashboard. </p> <pre><code>routes.rb root :to =&gt; "pages#home" </code></pre> <p>And pages#home is where the user's feed is located: @feed_items = current_user.feed</p> <pre><code>PagesController def home @title = "Home" @featured_posts = Post.featured.limit(10) if user_signed_in? @user = current_user @post = current_user.posts.build @feed_items = current_user.feed.paginate(:per_page =&gt; "10", :page =&gt; params[:page]) end end </code></pre> <p>Now I've figured out how to parse the feed and pull out a subset-feed that contains only the posts with category_id '2' (also know as 'thriller')</p> <pre><code> @thriller_feed_items= current_user.feed.where(:category_id =&gt; '2') </code></pre> <p>When a logged in user goes to the root_path they see their dashboard and entire feed. I'd like there to be a link that says 'thrillers' that will change the current entire @feed_items into the @thriller_feed_items but I'm confused about how the routes and views would work. Twitter uses /!#/mentions as the address for sub-set feeds, do I need to do the same thing? How would I set this up? </p> <p>EDIT: to show how my feed method works.</p> <p>User model</p> <pre><code> def feed Post.from_users_followed_by(self) end </code></pre> <p>Post model</p> <pre><code> def self.followed_by(user) followed_ids = %(SELECT followed_id FROM relationships WHERE follower_id = :user_id) where("user_id IN (#{followed_ids}) OR user_id = :user_id", :user_id =&gt; user) end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload