0

Rails 3.2.3を使用していて、HABTMの関係に問題があります。

基本的に、私はユーザーモデルを持っており、ロールモデルを備えたHABTMを持っています。

すべて正常に機能しますが、ユーザーモデルとホテルモデルの間に別のHABTM関係を追加したいと思います。

ページを実行しようとした場合を除いて、(tail -f log / 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

私のホテルモデル:

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

この新しい関係まで、すべてがうまくいっていました。プロジェクト内のページをまったく実行できません。任意のヒント?

皆さん、ありがとうございました。

4

1 に答える 1

2

スプリット:

 has_and_belongs_to_many :roles, :hotels

2行で:

 has_and_belongs_to_many :roles
 has_and_belongs_to_many :hotels
于 2012-05-08T18:24:19.793 に答える