I have 2 models.
class Company < ActiveRecord::Base
has_many :accounts, :class_name => "CompanyAccount"
end
class CompanyAccount < ActiveRecord::Base
belongs_to :company
end
In routes.rb
resources :companies do
resources :accounts
end
I have companies_controller.rb and accounts_controller.rb.
The following line doesn’t work because @account’s class is not Account but CompanyAccount.
= form_for [@company, @account] do
What’s the best way to resolve this name mismatch?
Thanks.
The problem is in your routes.rb file,
The code should still be
It does not matter what you name in your association has_many <association_name>, the resource name should always reflect the name of your actual model and not the ActiveRecord association. Hope it helps!