2014-09-26 41 views
1

我有一個奇怪的錯誤與軌道4燈具。Rails沒有正確加載4個燈具文件之一

events.yml:

work: 
    name: "work" 
    date_start: 2015-04-21 17:20:18 
    date_end: 2015-04-21 18:20:18 
    comment: test comment 
    admin: egor 
    users: [egor] 

users.yml裏:

egor: 
    email: [email protected] 
    encrypted_password: <%= User.new.send(:password_digest, '12345') %> 
    first_name: Egor 

這些陽明的偉大工程。 但是當我嘗試加載該文件

events_users.yml:

one: 
    user: egor 
    event: work 

我得到異常

ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'user' in 'field list': INSERT INTO `events_users` (`user`, `event`) VALUES ('egor', 'work') 

這裏是我的EventsUsers.rb模型(這是類似於其他文件)

class EventsUsers < ActiveRecord::Base 
    belongs_to :event 
    belongs_to :user 
end 
+0

你有移民嗎?你運行過它們嗎?你運行過'rake db:test:prepare'嗎? – 2014-09-26 11:32:43

+0

嘗試將模型類重命名爲EventsUser,將模型文件重命名爲app/models/events_user.rb,並將fixture文件重命名爲test/fixtures/events_user.yml。 – blowmage 2014-09-26 12:34:13

+0

按照答案中的建議進行重命名。英語不是我的強項之一=) – 2014-09-26 13:28:47

回答

1

型號名稱應該是單數,而不是複數。所以我猜測Rails根本找不到User和EventsUsers之間的鏈接(這會讓我的頭部甚至會像這樣打字)。它不知道user是一個對象引用,因爲它不會將「EventsUsers」識別爲與用戶模型關聯的有效模型。

我假設你在這裏做has_many :through關係?我建議使:through選項成爲例如「user_event」(以及名爲「UserEvent」的模型),或者甚至更好的描述如「outing」(以及名爲「Outing」的模型)。嘗試說出您的域唯一的語言。

無論如何,一旦您將模型名稱恢復爲傳統,單數形式Rails應該知道如何找到它,並且應該能夠在燈具中自行建立連接。