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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:39:44+00:00 2026-06-03T09:39:44+00:00

Im using rails 3.2.3 and am having issues with HABTM relationships. Basically, I have

  • 0

Im using rails 3.2.3 and am having issues with HABTM relationships.

Basically, I have a User model, with has a HABTM with a Role model.

Everything works fine, however, I now want to add another HABTM relation between the User model and the Hotel model.

Except for when I try to run my page I get a (tail -f log/development.log):

NoMethodError (undefined method `[]' for :hotels:Symbol):
  app/models/user.rb:7
  config/routes.rb:6
  config/routes.rb:1

My routes:

Oops::Application.routes.draw do #this is my line 1
  get "managers/index"

 root :to => "hotels#index"

  devise_for :users #this is my line 6
  resources :roles
  resources :users
  resources :managers
  resources :hotels

  ActiveAdmin.routes(self)

My User model:

devise :database_authenticatable, :recoverable, (...)

has_and_belongs_to_many :roles, :hotels #This is my line 7, if I delete :hotels and all its references in this HABTM relationship, everything works

accepts_nested_attributes_for :roles

attr_accessible :username, :email, :password, :password_confirmation, :remember_me, :role_ids, :hotel_attributes

My Hotel model:

has_and_belongs_to_many :facilities, :users
  has_one :address
  accepts_nested_attributes_for :facilities, :address, :users
  attr_accessible <all hotel attributes>, :facility_ids, :address_attributes, :user_ids

Everything was working up until this new relationship. I can’t run any page in the project at all.
Any tips?

Thank you all.

  • 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-03T09:39:45+00:00Added an answer on June 3, 2026 at 9:39 am

    Split:

     has_and_belongs_to_many :roles, :hotels
    

    on two lines:

     has_and_belongs_to_many :roles
     has_and_belongs_to_many :hotels
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some issues with routing in Rails. I already have a model in
I'm using rails 3.2.3 and am having issues with mass assignement. I have a
I am using Rails v2.3.2 . I have a model called UsersCar : class
So, I am having some issues with user authentication in embedded documents. I have
I am having some issues with nested models in a form, using Rails 3.1rc4.
I'm using bootstrap-sass to integrate Twitter Bootstrap in Rails but I'm having issues with
I'm having some issues using rails validation on a form. What I'm doing is,
I am having issues with my Rails 3.1 app. I have two controllers &
I'm having a ton of issues with Devise, using OmniAuth, to authenticate my Rails
Using RAILS 2.2 Hello I am having an issue where my dates are being

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.