-1

I have two models Hotel and Theme and I have applied has_and_belongs_to_many association on it.

My migration is

class CreateHotelsThemesTable < ActiveRecord::Migration
  def up
    create_table :hotels_themes, :id => false do |t|
        t.references :hotel
        t.references :theme
    end
    add_index :hotels_themes, [:hotel_id, :theme_id]
    add_index :hotels_themes, :hotel_id
  end

  def down
    drop_table :hotels_theme
  end
end

And models are:

class Theme < ActiveRecord::Base
  attr_accessible :theme_names
  has_and_belongs_to_many :hotels
end



class Hotel < ActiveRecord::Base
  attr_accessible :hotel_name, :stars, :location
  validates :hotel_name, :stars, :location, :presence => true
  has_and_belongs_to_many :thumes
end

Where some records are:

theme
=> #<Theme id: 5, theme_names: "Friends", created_at: "2013-08-24 20:13:00", updated_at: "2013-08-24 20:13:00">

    hotel
=> #<Hotel id: 2, hotel_name: "vijay shree1", stars: "2", location: "South Goa", created_at: "2013-08-24 15:59:53", updated_at: "2013-08-24 15:59:53">

When I run

>> theme.hotels
=> [#<Hotel id: 2, hotel_name: "vijay shree1", stars: "2", location: "South Goa", created_at: "2013-08-24 15:59:53", updated_at: "2013-08-24 15:59:53">]

working but when I run

>> hotel.themes
!! #<NoMethodError: undefined method `themes' for #<Hotel:0x007f6cd007c080>>

I am not getting why this is happening I have used has_and_belongs_to_many association. Thank in advance for help me.

Vijay Chouhan
  • 4,613
  • 5
  • 29
  • 35

1 Answers1

4

It seems there is a typo: has_and_belongs_to_many :thumes.

I think this is a cause of your problem

phts
  • 3,889
  • 1
  • 19
  • 31