I have the following three models:
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
When I open the users#show action I get the following error:
ActiveRecord::HasManyThroughAssociationNotFoundError in Users#show
Showing /Users/fanboy/Sites/ndt_app_v6/app/views/users/show.html.erb where line #14 raised:
Could not find the association :accociations in model User
Extracted source (around line #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>
Basically I would like to allow Users to associate themselves with a Pharmacy. Instead I get the error above, any help would be much appreciated.
Your comment is way off, and the linked documentation has nothing to do with your problem.
The problem with your code is that you have a brutally obvious typo in several places. Your association is called
associations, but your:throughusesaccociations.Associations vs ACCociations.
Rails is telling you exactly what the error is:
The reason your linked documentation fixed your problem is that you probably spelled the new association name correctly. It’s pretty important that you spell things correctly when programming, and such an obvious typo should really leap out at you.