我正在写一个关键字搜索算法。关键字存储在keywords
表/模型中,提交(发生搜索的地方)存储在submissions
表/模型中。还有一个submission_keywords
表格可以submissions
根据(我很确定)设置keywords
通过它们的独特链接。但是,当我尝试在我的视图中显示for a时:ids
has_many :through
keywords
submission
Show
<p>
<b>Keywords:</b>
<% @submission.keywords.each do |kw| %>
<%= kw.name %>
<% end %>
</p>
我收到一个错误:
ActiveRecord::HasManyThroughAssociationNotFoundError
Could not find the association :submission_keyword in model Submission
这是我对这 3 个模型的代码:
提交.rb:
class Submission < ActiveRecord::Base
attr_accessible :count, :is_sent, :is_success, :stamp, :url
has_many :submission_keywords, :dependent => :destroy
has_many :keywords, :through => :submission_keyword
end
关键字.rb:
class Keyword < ActiveRecord::Base
attr_accessible :name, :priority, :type
has_many :submission_keywords, :dependent => :destroy
has_many :submissions, :through => :submission_keyword
end
Submission_Keyword.rb
class SubmissionKeyword < ActiveRecord::Base
attr_accessible :freq, :keyword_id, :submission_id, :weight
belongs_to :submission
belongs_to :keyword
end
这是在视图中请求keywords
a的代码:submission
我看过很多帖子,人们忘记包含has_many
与:through
模型的关联,但正如你所见,我已经涵盖了这一点。知道可能出了什么问题吗?