ruby-on-rails – Rails有很多错误

ruby-on-rails – Rails有很多错误,第1张

概述似乎我已经将源定义为AR错误消息,但仍然会出现错误.任何的想法? Rails 3.2, Ruby 1.9.2 class Document < ActiveRecord::Base has_many :participations has_many :users, :through => :participations has_many :editing_se 似乎我已经将源定义为AR错误消息,但仍然会出现错误.任何的想法? Rails 3.2,Ruby 1.9.2

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有很多错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1274241.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存