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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:33:19+00:00 2026-05-13T16:33:19+00:00

I have a User Model(:name, :password, :email), and Event model(:name, :etc) and Interest model

  • 0

I have a User Model(:name, :password, :email), and Event model(:name, :etc) and Interest model (:name) [>all singular<]

Then I created two join tables -> UsersInterests and EventsInterests; each not containing a primary key and only comprised of the user_id/interest_id and event_id/interest_id respectively. [>plural<]

My Models Use the Nested Has Many Through Plugin

user.rb => has_many :users_interests
 has_many :interests, :through => :users_interests
 has_many :events_interests, :through => :interests
 has_many :events, :through => :events_interests

event.rb => has_many :events_interests
  has_many :interests, :through => :events_interests
     has_many :users_interests, :through => :interests
  has_many :users, :through => :users_interests

interest.rb => has_and_belongs_to_many :users
               has_and_belongs_to_many :events

events_interests.rb => belongs_to :interests
                    belongs_to :events
users_interests.rb => belongs_to :users
                   belongs_to :interests

Whew..ok So I wanted to created a named_scope of that find all the events that share interest with a particular user. Here is some code someone helped me with.

named_scope :shares_interest_with_users, lambda {|user|
{ :joins => :users_interests,
  :conditions => {:users_interests => {:user_id => user}}
   }}

When i run from the controller =>

@user = User.find(1) 
@events = Event.shares_interest_with_user(@user)

I get the error :

uninitialized constant Event::EventsInterest

Can anyone see what i messed up?

  • 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-13T16:33:20+00:00Added an answer on May 13, 2026 at 4:33 pm

    You must have named something wrong along the way. At a glance I’d say you have a file or class named incorrectly. Remember model names MUST always be singular, both in file and class names or else Rails won’t make the connection. Another source of your problem is that arguments to belongs_to must also be singular. Even if you had got things right, the HABTM relationship in interests with users would have thrown an error when you ran the named scope.

    I was able to solve your error with the following models.

    user.rb

    class User < ActiveRecord::Base
    has_many :users_interests
      has_many :interests, :through => :users_interests
      has_many :events_interests, :through => :interests
      has_many :events, :through => :events_interests
    end
    

    users_interest.rb

    class UsersInterest < ActiveRecord::Base
      belongs_to :user
      belongs_to :interest
    end
    

    interest.rb

    class Interest < ActiveRecord::Base 
      has_many :users,:through => :users_interests
      has_many :users_interests
      has_many :events_interests
      has_many :events, :through => :events_interests
    end
    

    **events_interest.rb

    class EventsInterest <ActiveRecord::Base
      belongs_to :interest
      belongs_to :event
    end
    

    event.rb

    class Event <ActiveRecord::Base 
      has_many :events_interests
      has_many :interests, :through => :events_interests
      has_many :users_interests, :through => :interests
      has_many :users, :through => :users_interests
    
    
      named_scope :shares_interest_with_users, lambda {|user|
        { :joins => :users_interests,
          :conditions => {:users_interests => {:user_id => user}}
        }
      }
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a User Model(:name, :password, :email), and Event model(:name, :etc) and Interest model
My User model contains :name, :email, and :password fields. All 3 have validations for
Suppose you have two models, User and City, joined by a third model CityPermission:
So I have a User model that :has_many other models like Documents, Videos, Posts
For example, if I have a user model and I need to validate login
I have a model Foo which have a ForeignKey to the User model. Later,
In my user model, I have an attribute called nickname and validates as such:
I have a data model that includes common columns like addedBy, editedby (user), addedDate,
I have two models indexed for searching (User and Item). I'm trying to do
I have user control named DateTimeUC which has two textboxes on its markup: <asp:TextBox

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.