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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:54:54+00:00 2026-05-16T17:54:54+00:00

I have a simple has_many through relationship set up: class Tag < ActiveRecord::Base has_many

  • 0

I have a simple has_many through relationship set up:

class Tag < ActiveRecord::Base
  has_many :profile_tags
  has_many :profiles, :through => :profile_tags
end

class ProfileTags < ActiveRecord::Base
  belongs_to :profile
  belongs_to :tag
end

class Profile < ActiveRecord::Base
  has_many :profile_tags
  has_many :tags, :through => :profile_tags
end

From my view I am accepting a set of tags (just strings), and am iterating over them in my controller and calling Tag.create( … ) on each of them, and pushing them into an array. This all works fine.

So I get to a point where I have an Array of Tag objects (tags) which were each returned by the call to create, and variable @profile which was created by doing Profile.new

I would like to do: @profile.tags = tags

Doing this causes this error on the line where I try the assignment:

uninitialized constant Profile::ProfileTag

Rails is acting like I need to manually create and assign the join table association, even though here http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association it states that when you do an assignment like this, new associations will be created and if some are gone they will be deleted.

Any ideas what I could be doing wrong here?

  • 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-16T17:54:54+00:00Added an answer on May 16, 2026 at 5:54 pm

    Rails assumes that model classes are named with the singular form, i.e. the class ProfileTags should be called ProfileTag.

    Depending on which Rails version you are using, probably the easiest way to fix this is to re-create the model using script/destroy and script/generate in Rails 2.x or rails destroy and rails generate in Rails 3.

    Alternatively, specifying the class name manually by adding :class_name => 'ProfileTags' to the has_many declarations should work too.

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

Sidebar

Related Questions

I have a basic has_many through relationship: class Foo < ActiveRecord::Base has_many :bars, :dependent
I have the following simple models: class Event < ActiveRecord::Base has_many :participations has_many :users,
Alright so I have a simple has_many :through relationship in Rails 3.1 class Event
I have a simple rails application were book belongs_to user and user has_many book.
I have a simple has_one/belongs_to relationship between two models. This is a new association
I have a store model that has many products with a has_many :through relationship.
Is there a simple way to specify a has_many :through relationship where you're linking
I am setting up a simple has_many through relationship. I was wondering if there
noob question here. I have a has_many :through relationship between items and tags. Finding
I have a typical many-to-many relationship using has_many => :through , as detailed below.

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.