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.

Silver
  • 693
  • 1
  • 10
  • 27

1 Answers1

2

Split:

 has_and_belongs_to_many :roles, :hotels

on two lines:

 has_and_belongs_to_many :roles
 has_and_belongs_to_many :hotels
jdoe
  • 15,665
  • 2
  • 46
  • 48