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 4626626
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:26:53+00:00 2026-05-22T03:26:53+00:00

Hi I am very new rails , would need some help , there is

  • 0

Hi I am very new rails , would need some help , there is nothing similar I could find , i watch all the rail casts on the similar lines.

So I have a article model and user model ( devise ) .

I would to user to add article either in Follow Mode or Just Read Later Mode.

so UserArticleAssociation has article_id , user_id and association type . I am not understanding how to implement this feature correctly. I could make some hack to do these , but I don’t want to.

Any tutorial on similar will be great help.

  • 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-22T03:26:53+00:00Added an answer on May 22, 2026 at 3:26 am

    Try this:

    class User < ActiveRecord::Base
      has_many :user_articles
    
      has_many :read_user_articles, :class_name => "UserArticle", 
                  :conditions => {:mode => "read"}
    
      has_many :follow_user_articles, :class_name => "UserArticle", 
                  :conditions => {:mode => "follow"}
    
      has_many :articles,       :through => :user_articles
    
      has_many :read_articles,  :through => :read_user_articles, :source => :article
      has_many :follow_articles,:through => :follow_user_articles,:source => :article
    
    end    
    
    # Add a column called mode of type string (follow, read)
    class UserArticle < ActiveRecord::Base
      belongs_to :user
      belongs_to :article
    end
    
    class Article < ActiveRecord::Base
      has_many :user_articles
      has_many :read_user_articles, :class_name => "UserArticle", 
                  :conditions => {:mode => "read"}
    
      has_many :follow_user_articles, :class_name => "UserArticle", 
                  :conditions => {:mode => "follow"}
    
      has_many :readers,  :through => :read_user_articles, :source => :user
      has_many :followers,:through => :follow_user_articles,:source => :user
    end
    

    Now you can do the following:

    To add an article to read/follow category:

    user.read_articles << article
    user.follow_articles << article
    

    OR

    article.reader << user
    article.follower << user
    

    To access the articles

    user.read_articles
    user.follow_articles
    

    To access the users

    article.readers
    article.followers
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, let me say I am very new to rails, have been
I'm very new with rails and I've been building a CMS application backend. All
There's a new dsl in capybara 1.0.0.rc1 that's very similar to steak. I'm trying
I'm very new to Ruby on Rails so please go easy! I've uploaded the
Relatively new to rails and trying to model a very simple family tree with
I am absolutely and totally new to rails, so the answer is probably very
I have built a very simple blog application using Ruby on Rails. New to
Very new to JQuery and MVC and webdevelopment over all. I'm now trying to
Im very new to SQL but need to write a query to do the
I am very new to Rails and Cucumber so this may or may not

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.