Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6655193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:29:13+00:00 2026-05-26T01:29:13+00:00

I’ve created a small twitter clone app where users make posts, follow other users,

  • 0

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.

When a user is logged in, the root web address is their dashboard.

routes.rb

root :to => "pages#home"

And pages#home is where the user’s feed is located: @feed_items = current_user.feed

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 => "10", :page => params[:page])
    end
end

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’)

 @thriller_feed_items= current_user.feed.where(:category_id => '2')

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?

EDIT: to show how my feed method works.

User model

  def feed
    Post.from_users_followed_by(self)
  end

Post model

   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 => user)
    end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:29:13+00:00Added an answer on May 26, 2026 at 1:29 am

    I’m assuming at this point that this controller is non-RESTful.

    Edit: I’ve updated this to also allow a category name. Adjust routes and variable indices accordingly.

    Routes.rb

    match "/category/:category" => "pages#home"
    

    Pages#home

    def home
      @title = "Home"
      @featured_posts = Post.featured.limit(10)
      if user_signed_in?
        @user = current_user
        @post = current_user.posts.build
        # BEGIN NEW
        if params[:category]
          # is :category an integer id?
          if params[:category].to_i.to_s == params[:category]
            @feed_items= current_user.feed.where(:category_id => params[:category])
          else
            # assuming Category has_many :feeds
            @feed_items= current_user.feed.includes(:category).where(
              ['`categories`.name = ?', params[:category]]
            )
          end
        else
          @feed_items = current_user.feed
        end
        @feed_items = @feed_items.paginate(:per_page => "10", :page => params[:page])
        # END NEW
      end
    end
    

    View:

    <%= link_to "Thriller Feed Items (by id)", "/category/2" %>
    <%= link_to "Thriller Feed Items (by name)", "/category/Thriller" %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a text area in my form which accepts all possible characters from
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.