class Gallery < ApplicationRecord
belongs_to :artist
include Filterable
validates :user, presence: true
belongs_to :user, optional: true
resourcify
end
我將如何種子具有多個belongs_to
的數據? 這是我的方法,但它給了我一個錯誤,用戶不能爲空有多個rails5播種數據belongs_to
user = User.create! :name =>'Bobby Joe',:email => '20 @ gmail.com',:password =>'password',:password_confirmation =>'password'
artistOne = user.artists.create!(artist_name :'ED',first_name:'Edgar',姓氏:'Degas',電子郵件:'[email protected]',密碼:'密碼',街道:'2625 Ashcraft',城市:'聖地亞哥',州:'' CA',郵編:'92103',網站:'www.edgardegas.com',銷售:'',電話:'(760)210-1326')
galleryOne = artistOne.galleries.create!(name: '藝術展',網站:'www.ExhibitionOfArt.com',電話:'(619)264-8402',開幕式:'10:00:00',結束時間爲'18:00:00',街道:'' 325 15th Street',城市:'聖地亞哥',州:'CA',郵政編碼:'92101')
你有藝術家模型中的字段user_id嗎? – Gabbar