Answer the question
In order to leave comments, you need to log in
Error: Unknown attribute in ActiveRecord(ruby). How to fix?
Hello.
There are the following models:
class Contractor < User<br>
has_many :contractorEs<br>
has_many :customers<br>
end<br><br>
class Customer < User<br>
belongs_to :contractor<br>
has_many :customerEs<br>
end<br>
class AddContractorIdToCustomers < ActiveRecord::Migration<br>
def change<br>
add_column :customers, :contractor_id, :integer<br>
end<br>
end<br>
c = Contractor.first<br>
c.customers.build<br>
ActiveRecord::UnknownAttributeError: unknown attribute: contractor_id<br>
<Customer id: nil, first_name: nil, last_name: nil, address: nil, country: nil, zip: nil, city: nil, phone: nil, company_name: nil, signature: nil, type: "Customer", created_at: nil, updated_at: nil, v_token: nil, password_digest: nil, u_token: nil, email: nil, state: "new"><br>
Answer the question
In order to leave comments, you need to log in
strong_params?
def contractor_params
params.require(:contractor).permit(:contractior_id)
end
what version of rails? if 3, then perhaps you need to add it to Customer
attr_accessible :contractor_id
replace
has_many :contractorEs
has_many :contractors
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question