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

  • SEARCH
  • Home
  • 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 8399167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:13:43+00:00 2026-06-09T21:13:43+00:00

I am using Ruby on Rails 3.2.2 and I would like to know what

  • 0

I am using Ruby on Rails 3.2.2 and I would like to know what is a common approach in order to handle associated objects of a has_many :through ActiveRecord::Association. That is, I have:

class User < ActiveRecord::Base
  has_many :article_editor_associations, :class_name => 'Articles::UserEditorAssociation'
  has_many :articles, :through => :article_editor_associations
end

class Article < ActiveRecord::Base
  has_many :user_editor_associations, :class_name => 'Articles::UserEditorAssociation'
  has_many :editor_users, :through => :user_editor_associations
end

class Articles::UserAssociation < ActiveRecord::Base
  belongs_to :editor_users
  belongs_to :articles
end

By using the above code, I can run the @article.editor_users method so to retrieve an Array of Editor Users. However, in order to make things to fit better with my application (that is, for example, in order to handle things like I18n translations and similar in a “programmatic” way), I am thinking to add to my application a new model like the following:

class EditorUser < User # Note the class name and the class inheritance
  ...
end

This way, through my application, I can refer to the EditorUser class in order to handle article “editor user” instances as if they were User objects… more, since inheritance, in the EditorUser class I can state “specific methods” (for example, scope methods) available only to EditorUser instances (not to User instances)…

Is it a “common” approach to make things as I would like to make in my case? Is it the “Rails Way”? If so, what I could / should make to handle this situation? If no, how could / should I proceed?


In other words, I thought using class EditorUser < User ... end because associated EditorUser objects (retrieved by running the @article.editor_users method) are User objects. I think that by stating a EditoUser class in the app/models directory (or elsewhere) could simplify things in my application because you can work around that constant name (for example, you can “play” with that constant name in order to “build” translation strings or by stating new methods just to be used for EditorUser instances).

  • 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-06-09T21:13:45+00:00Added an answer on June 9, 2026 at 9:13 pm

    With Rails, I’ve learned to focus on the naming conventions and standard usage first (‘convention’ over configuration) and would set it up like this:

    class User < ActiveRecord::Base
      has_many :editors
      has_many :articles, :through => :editors
    end
    
    class Article < ActiveRecord::Base
      has_many :editors
      has_many :users, :through => :editors
    end
    
    class Editor < ActiveRecord::Base
      belongs_to :user
      belongs_to :article
    end
    

    You can either use the presence of the join record, e.g. User.editor or add an additional attribute to editor if you want different editor access levels.

    The above does not fully answer your question perhaps but should be a good starting point. I say this because one of the most important things about rails is that it uses a principle of ‘convention over configuration’. This is good as it leads to terse, minimalist code. It’s bad because you have to learn all the zillion conventions. If you don’t know them or the framework well you can get yourself into a whole heap of trouble as I have seen with many rails applications that I have worked on over the years.

    So my advice is really to step back. Don’t try and force things to work with things like class renames. If the setup I have shown doesn’t meet your needs, revisit your needs and read more on active record and associations in the API. I know this can be kinda frustrating for quite a while with rails but you really need to look how to do things the right way if you’re going to be a good rails programmer in the long term.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Ruby on Rails 3.2.2 and I would like to know if
I am using Ruby on Rails 3.2.2 and I would like to know what
I am using Ruby on Rails 3.2.2 and I would like to know if
I am using Ruby on Rails 3.2.2. and I would like to know if
I am using Ruby on Rails 3.1 and I would like to know (for
I am using Ruby on Rails 3.0.7 and I would like to know what
I am using Ruby on Rails 3.2.2 and I would like to know if
I am using Ruby on Rails 3.2.2 and I would like to know if
I am using Ruby on Rails 3.0.7 and I would like to know how
I am using Ruby on Rails 3.0.7 and I would like to know what

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.