正在經歷http://guides.rubyonrails.org/association_basics.html但似乎無法讓我解決這個Rails的活動記錄的關聯,嵌套模型
的頭,我有4種型號:用戶列表,評論,commentresponses。有人創建列表,其他人可以對列表發表評論,然後原始創建者可以對評論做出迴應。
class User < ActiveRecord::Base
has_many :comments, foreign_key: 'provider'
has_many :listings
has_many :comments
has_many :commentresponses
end
class Listing < ActiveRecord::Base
belongs_to :user
end
class Comment < ActiveRecord::Base
belongs_to :listing
belongs_to :user
has_one :commentresponse
end
class Commentresponse < ActiveRecord::Base
belongs_to :comment
belongs_to :user
end
一切運轉良好,除非我無法訪問comment.commentresponse;這給了一個沒有方法的錯誤。
任何關於我的邏輯錯誤的建議?
這段代碼看起來不錯,你可以粘貼確切的錯誤信息? –