我有以下三个模型:
class User < ActiveRecord::Base
has_many :associations
has_many :pharmacies, :through => :accociations
end
class Associations < ActiveRecord::Base
belongs_to :user
belongs_to :pharmacy
end
class Pharmacy < ActiveRecord::Base
has_many :associations
has_many :users, :through => :accociations
end
当我打开users#show
操作时,我收到以下错误:
ActiveRecord::HasManyThroughAssociationNotFoundError 在用户#show
显示 /Users/fanboy/Sites/ndt_app_v6/app/views/users/show.html.erb 其中第 14 行提出:
找不到关联:模型用户中的关联
提取的源代码(在第 14 行附近):
11: <div class="span8"> 12: <%= form_for(@user) do |f| %> 13: <%= f.label :pharmacy_ids, "Pharmacies" %><br /> 14: <%= f.collection_select :pharmacy_ids, Pharmacy.order(:name), :id, :name, {}, {multiple: true} %> 15: <% end %> 16: </div> 17: </div>
基本上我想让用户将自己与药房联系起来。相反,我得到了上面的错误,任何帮助将不胜感激。