我得到了與聯賽ActiveModel :: MissingAttributeError:不能寫未知屬性`user_id`?
create_table "leagues", force: :cascade do |t|
t.string "name", null: false
t.date "start_date", null: false
t.date "end_date"
t.string "day"
t.string "start_time", null: false
t.integer "practice_length", null: false
t.integer "alley_id", null: false
t.integer "frequency", null: false
t.integer "scratch", default: 220
t.integer "handicap_percent", default: 80
t.integer "handicap_round", default: 0
t.integer "occurrences", null: false
t.integer "user_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
和模型
class Alley < ActiveRecord::Base
belongs_to :address
has_many :leagues
end
class User < ActiveRecord::Base
has_many :leagues
end
class League < ActiveRecord::Base
belongs_to :alley
belongs_to :user
has_many :teams
end
和工廠
factory :league do
name Faker::Company.name
start_date start_date
end_date end_date
day Date.today.day
start_time '7:00pm'
practice_length 10
frequency 1
occurrences weeks
association :alley, factory: :alley
association :user, factory: :user
end
factory :user do
email '[email protected]'
password 'Test1234'
password_confirmation { 'Test1234' }
end
factory :alley do
name Faker::Company.name
association :address, factory: :address
end
當我嘗試創建一個聯賽,我得到一個錯誤的模式
ActiveModel::MissingAttributeError: can't write unknown attribute
user_id
它的設置就像衚衕一樣,衚衕也很有用。一個聯盟應該被分配到一個衚衕並分配給一個用戶。一條小巷可以有很多聯賽,一個用戶可以有很多聯賽。坦率地說,我太累了,不知道爲什麼這個目前不能工作。
你能更新'user'的工廠嗎? –
是的,我可以更新它,以什麼? – TIMBERings
是的,我只是想看到它更清晰,順便說一句,你可以重新檢查'user_id'在你的架構中,'ActiveModel :: MissingAttributeError'表明像'user_id'丟失! –