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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:28:33+00:00 2026-05-29T19:28:33+00:00

I am trying to create a has_many :through association so that my Users can

  • 0

I am trying to create a has_many :through association so that my Users can keep track of Domains by creating the association when they add them on their account page.

I have the following models:

models/user.rb

class User < ActiveRecord::Base
  attr_accessor :password
  attr_accessible :name, :email, :password, :password_confirmation

  has_many :domain_followings, :foreign_key => "domain_id"
  has_many :domains, :through => :domain_followings

models/domain_followings.rb

class DomainFollowings < ActiveRecord::Base
  attr_accessible :domain_id

  belongs_to :user
  belongs_to :domain
end

models/domain.rb

class Domain < ActiveRecord::Base
  attr_accessible :name

  has_many :domain_followings, :foreign_key => "user_id"
  has_many :users, :through => :domain_followings

I get errors like the following in my specs:

   1) Users signup success should make a new user
     Failure/Error: click_button
     NameError:
       uninitialized constant User::DomainFollowing
     # ./app/controllers/users_controller.rb:32:in `show'
     # ./spec/requests/users_spec.rb:32
     # ./spec/requests/users_spec.rb:26

The code in question is here:

  def show
    @user = User.find(params[:id])
    @title = @user.name
    @domain = Domain.new if signed_in?
    @domains = @user.domains.paginate(:page => params[:page])
  end

The uninitialized constant User::DomainFollowing is repeated several times for other code.
Ideally I would like my code to require a user association in the domain_followings table before allowing a domain to be created in the domain table. Is this possible?

  • 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-29T19:28:34+00:00Added an answer on May 29, 2026 at 7:28 pm

    Solution was to rename the relationship model to models/domain_following.rb, making it singular. Also removed foreign_key declarations following Bladrick’s suggestion. Everything flows smoothly now.

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

Sidebar

Related Questions

I'm trying to create a Users table that only has OpenId registrations, exactly like
I setup a has_many through association with my models and I am trying to
I'm trying to create a new picture record within my gallery. Users can create
I'm trying to create a form that has an expandable widget. The problem is
I am trying to create a report that has a summary for each group.
I'm trying to create a relation that has a between join. Here is a
I'm trying to create an HBox in flex that has only the top corners
I'm trying to create a css menu bar that has all grey text with
I am trying to create a very simple chat window that simply has the
I am trying to create a simple Android application that has a ActivityList of

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.