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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:18:40+00:00 2026-06-08T08:18:40+00:00

I’m a newcomer to Ruby just using this forum to help understand the language

  • 0

I’m a newcomer to Ruby just using this forum to help understand the language while I code a sample application to hone my skills.

I’ve tried to set up a has many relationship between Product & Media. I suspect the challenge I”m having is because of the plural form medium, but not sure how to troubleshoot it.

class CreateMedia < ActiveRecord::Migration
  def change
    create_table :media do |t|
      t.string :type
      t.string :alt
      t.boolean :is_primary
      t.string :url_tiny
      t.string :url_small
      t.string :url_regular
      t.string :url_large
      t.string :title

      t.timestamps
    end
  end
end

 class Media < ActiveRecord::Base
  attr_accessible :alt, :is_primary, :title, :type, :url_large, :url_regular, :url_small, :url_tiny
  belongs_to :product
end

class Product < ActiveRecord::Base
   attr_accessible :assoc_product,:product_id, :merch_associations, :aux_description, :buyable, :long_description, :name, :on_special, :part_number, :release_date, :short_description, :withdraw_date, :occasion
  has_and_belongs_to_many :categories
  has_many :merch_associations
  has_many :assoc_products, :through => :merch_associations
  has_many :media
 ...

When I run this (note dress_media is a populated Media object array):

 products[i].media << dress_media[m]

I get this in the error console:

uninitialized constant Product::Medium

I looked in the DB and the table is indeed called Media, not medium. So I thought it should have been the plural right? (This code was generated from the rails generator)

Like I say I’m new to Rails so if someone can point me in the right direction to create this one to many between Product & Media, that would be great?

  • 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-08T08:18:41+00:00Added an answer on June 8, 2026 at 8:18 am

    As I understand, you have a model called ‘Media’. Note that ‘Media’, as you mention in your question, is already a plural. The correct would be having a model called ‘Medium’ and the following relationships:

    class Medium < ActiveRecord::Base
        attr_accessible :alt, :is_primary, :title, :type, :url_large, :url_regular,:url_small, :url_tiny
        belongs_to :product
    end
    

    and

    class Product < ActiveRecord::Base
       attr_accessible :assoc_product,:product_id, :merch_associations, :aux_description,     :buyable, :long_description, :name, :on_special, :part_number, :release_date,     :short_description, :withdraw_date, :occasion
       has_and_belongs_to_many :categories
       has_many :merch_associations
       has_many :assoc_products, :through => :merch_associations
       has_many :media
       ...
    end
    

    At sometime you might want to set or overwrite Rails singularizations and pluralizations. I don’t recommend doing it in that specific case, but take a look at http://blog.thefrontiergroup.com.au/2011/06/pluralizations-and-singularizations-inflections-in-rails-3/ just to know how to do it.

    Note that if you create a model called ‘Medium’, the database table will be called ‘Media’.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,

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.