2012-05-18 76 views
0

當試圖在我的表單(模型也在下面列出)中構建'興趣'複選框列表時,出現以下錯誤...任何想法?謝謝!簡單的Rails SQL錯誤

ActiveRecord::StatementInvalid in User_steps#show 

Showing /Users/nelsonkeating/Desktop/ReminDeal/app/views/user_steps/show.html.erb where line #19 raised: 

SQLite3::SQLException: no such column: person_interests.interest_id: SELECT "interests".* FROM "interests" INNER JOIN "person_interests" ON "interests"."id" = "person_interests"."interest_id" WHERE "person_interests"."person_id" = 11 AND "person_interests"."person_type" = 'User' 
Extracted source (around line #19): 

16: <legend>Interests & Holidays</legend> 
17: <h4>Select your top 3 interests..</h4> 
18: 
19: <%= f.simple_fields_for :interests do |interest_f| %> 
20: <%= interest_f.input :interest, :as => :check_boxes, :label => false %> 
21: <% end %> 
22: <br></br> 



class User < ActiveRecord::Base 

    attr_accessible :name, :email, :password, :password_confirmation, :remember_me,  :interests_attributes, :city, :zipcode, :date_of_birth, :gender, :address, :interest_ids, :holiday_ids, :friends_attributes, :person_interest_ids, :friends 
    has_many :friends 
    has_many :person_interests, :as => :person 
    has_many :interests, :through => :person_interests 

    accepts_nested_attributes_for :friends, allow_destroy: true 
    accepts_nested_attributes_for :interests, allow_destroy: true 

end 

class PersonInterest < ActiveRecord::Base 
    attr_accessible :person_id, :person_type 
    belongs_to :interest 
    belongs_to :person, :polymorphic => true 
end 


class Interest < ActiveRecord::Base 
    attr_accessible :name 
    has_many :person_interests 
    has_many :people, :through => :person_interests 
end 
+0

我可能不知道的軌道縫補的事情,但根據你得到的錯誤,它的聲音,我喜歡你的'person_interests'表沒有名爲'interest_id'列。 – Travesty3

+0

你是否在最新的遷移? –

+0

是的,@Travesty3是正確的,我需要一個interest_id列..表格現在正在出現,但不保存到數據庫 – js111

回答

2

基於此錯誤消息:

的SQLite3 ::的SQLException:沒有這樣的列:person_interests.interest_id

看來,你person_interests表沒有名爲interest_id列。