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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:37:27+00:00 2026-06-02T15:37:27+00:00

I have a Ruby 1.9.3 on Rails 3.2.2 application and I am dealing with

  • 0

I have a Ruby 1.9.3 on Rails 3.2.2 application and I am dealing with a number of has_many associations that need to include a type. For example:

  • The user has many aircraft. The aircraft are of a certain type (Cessna 172).
  • The user has many licenses. The licenses are of a certain type (Private Pilot License).
  • The license has_many ratings. The ratings are of a certain type (Single Engine Piston-Class Rating).

My problem is with naming all these classes. Right now the associations on the user are named Aircraft, License and Rating, but that still requires me to name the type-classes. I initially had them named AircraftType, LicenseType and RatingType but this smelled to me.

Right now I have all these type classes in a dedicated module Types, so my type classes are now named Types::Aircraft, Types::License and Types::Rating but I am not sure if this has me heading for trouble down the road given the questionable support for namespacing in Rails I keep hearing of.

Is there a convention or standard practice for this sort of problem?

Update:

Because the list of aircraft types is regularly updated, I need these to be in the database. While the license types and ratings change less frequently, I would still prefer them to be in the database if I need to add, change or remove any. This kind of rules out defining them statically in the classes themselves.

  • 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-02T15:37:30+00:00Added an answer on June 2, 2026 at 3:37 pm

    You could put the types in the models as a class method, because they are so tightly associated with the model. Something like:

    class Aircraft < ActiveRecord::Base
      def self.XTypes
         ['Cessna 172','Cessna 152','Boeing 747']
      end
    end
    

    Just don’t use ‘type’, as rails has reserved that for single table inheritance, in fact ‘Types’ may even be dangerous, BUT, it would be nice to keep the attribute name the same for all of your models that have types, that at least opens up the possibility of DRYer code, you could possibly share some code between all the Models that have XTypes, like in a view helper that creates a select element for any model that has an XType.

    So, typically you’d use XTypes like this:

    <%= f.select 'xtype', Aircraft.XTypes %>
    

    The larger the list of XTypes, and the more prone they are to revisions/additions/deletions, you should probably consider putting them in a separate model and link them up with a has_one relationship, but if they are fairly static, the above approach would probably be fine.

    UPDATE:

    I think Single Table Inheritance may be the ticket, either that or just a simple has_one relationship. But it sounds like you want to condense all these types into a single entity, so you may want STI

    class mytype < ActiveRecord::Base; end
    class AircraftType < mytype; end
    class LicenseType < mytype; end
    

    You just have to add a string attribute called ‘type’ in your mytype model, and fill it in with the values ‘AircraftType’ or ‘LicenseType’. Now you have one model that can accommodate all of your types, i.e. if you’re editing a license record, and you want a select element of LicenseTypes, you could do:

    <%= f.select 'type', LicenceType.all().map {|t|, [t.id, t.description] }
    

    If you were editing an aircraft:

    <%= f.select 'type', AircraftType.all().map {|t|, [t.id, t.description] }
    

    This assumes the base mytype model has an attribute ‘description’

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

Sidebar

Related Questions

I have a Ruby on Rails application that has two active environments, Stage and
I have a ruby on rails application with an input text field that has
I have created a table in my Ruby on Rails application that I am
I have a RoR application (ruby v1.8.7; rails v2.3.5) that is caching a page
I have a RoR application running on box1...it obviously has Ruby, RubyGems, and Rails
I have a ruby-on-rails application that wishes to utilise the tumblr gem for adding
I have a Ruby on Rails application that I'm developing on my computer, which
I have a Ruby on Rails application that will be a CMS in way
I currently have a Ruby (Rails) application that needs to make a lot of
I have a Ruby on Rails application that allows for users to create a

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.