2012-05-08 3 views
0

나는 레일 3.2.3을 사용 중이며 HABTM 관계에 문제가 있습니다.Ruby on Rails - HABTM NoMethodError

기본적으로 사용자 모델이 있고 역할 모델이있는 HABTM이 있습니다.

그러나 모든 것이 잘 작동하지만 사용자 모델과 호텔 모델간에 또 다른 HABTM 관계를 추가하려고합니다. 제외

나는 내가 (꼬리 -f 로그/development.log 파일)을 얻을 내 페이지를 실행하려고하면

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

내 경로 :

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) 

내 사용자 모델 :

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 

내 호텔 모델 :

이 새로운 관계가 완성 될 때까지 모든 것이 이루어졌습니다. 프로젝트에서 페이지를 전혀 실행할 수 없습니다. 팁이 있습니까?

감사합니다.

답변

2

분할 :

has_and_belongs_to_many :roles 
has_and_belongs_to_many :hotels 
: 두 줄에

has_and_belongs_to_many :roles, :hotels