class document < ActiveRecord::Base has_many :participations has_many :users,:through => :participations has_many :editing_sessions has_many :editors,:through => :editing_sessions,:source => :users end class User < ActiveRecord::Base has_many :participations has_many :documents,:through => :participations has_many :editing_sessions has_many :open_documents,:source => :documents end class EditingSession < ActiveRecord::Base belongs_to :users belongs_to :documents end create_table "editing_sessions",:force => true do |t| t.integer "user_ID" t.integer "document_ID" t.datetime "created_at",:null => false t.datetime "updated_at",:null => false end Console: u = User.first => ... OK u.editing_sessions => [] u.open_documents => ActiveRecord::HasManyThroughSourceAssociationNotFoundError: Could not find the source association(s) :document in model EditingSession. Try 'has_many :open_documents,:source => <name>'. Is it one of :users or :documents?解决方法 尝试更改EditingSession定义,以便belongs_to标签采用单数形式:
class EditingSession < ActiveRecord::Base belongs_to :user belongs_to :documentend
但是以复数形式将其他源定义保留在document和Users类中(即:source =>:users和:source =>:documents)
这是Ruby on Rails Has-Many-Through Guide的惯例
总结以上是内存溢出为你收集整理的ruby-on-rails – Rails有很多错误全部内容,希望文章能够帮你解决ruby-on-rails – Rails有很多错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)