2013-06-12 3 views
7

काम नहीं कर रहा है मुझे रूबी ऑन रेल परियोजना में has_and_belongs_to_many एसोसिएशन के साथ समस्या है।has_and_belongs_to_many assocation

यहाँ मेरी मॉडल हैं:

class Store < ActiveRecord::Base 
    attr_accessible :address, :city, :map_url, :name, :uimage_url 
    has_and_belongs_to_many :furnitures_id 
end 

class Furniture < ActiveRecord::Base 
    attr_accessible :description, :image_url, :maintenance, :name, :size 
    has_and_belongs_to_many :store_id 
end 

यह मेरा में शामिल होने तालिका माइग्रेशन:

create_table "furnitures_stores", :id => false, :force => true do |t| 
    t.integer "furniture_id" 
    t.integer "store_id" 
end 

मैं तो seed.rb के साथ कुछ मूल्यों को सम्मिलित करने की कोशिश की:

Furniture.delete_all 
furnitures = Furniture.create([{name: 'aaaa 1'}]) 

Store.delete_all 
storee = Store.create([{name: 'S 1'}]) 

लेकिन यह काम नहीं करता है;

**rake aborted! 
uninitialized constant Store::FurnituresId** 

उत्तर

8

आप has_and_belongs_to_many :furnitures और has_and_belongs_to_many :stores जरूरत है: मैं इस त्रुटि है। आपको मॉडल को संदर्भित करने की आवश्यकता है, न कि विदेशी कुंजी।

अधिक जानकारी के लिए A Guide to ActiveRecord Associations देखें।

+0

लेकिन मैं मॉडल का संदर्भ कैसे दे सकता हूं? – Teo

+0

@ टीओ मुझे नहीं पता कि आपका क्या मतलब है। –

+0

अब मैं समझता हूं .. और यह काम करता है .. धन्यवाद – Teo

संबंधित मुद्दे