Error: Unknown attribute in ActiveRecord(ruby). How to fix?

Hello.

There are the following models:

class Contractor < User
 has_many :contractorEs
 has_many :customers
end

class Customer < User
 belongs_to :contractor
 has_many :customerEs
end


There is a migration:

class AddContractorIdToCustomers < ActiveRecord::Migration
 def change
 add_column :customers, :contractor_id, :integer
end
end


Try to create customer (Customer), for this I go to the console and do the following:

c = Contractor.first
c.customers.build


Is created the customer will receive the following error message:

ActiveRecord::UnknownAttributeError: unknown attribute: contractor_id


The migration ran, the server will have restartovat. Problem unfortunately remains.
Tell me, please, what it can be connected and how to fix it.

The rays of goodness to you :)

UPD: Ruby 2/Rails 4
UPD 2: I use STI, all inherited from User-a. Maybe the problem is related to this?
UPD 3: Continue to investigate the problem. It turned out that the model is created through the Customer.new in the boxes no contractor_id:

<customer id: nil, first_name: last_name: address: country: zip: city: phone: company_name: signature: type: "customer", created_at: updated_at: v_token: password_digest: u_token: email: state: "new">
</customer>


If Customer I will inherit from ActiveRecord::Base, everything works fine. But I need to inherit from User.
October 3rd 19 at 03:07
4 answers
October 3rd 19 at 03:09
strong_params?

 def contractor_params
params.require(:contractor).permit(:contractior_id)
end
The author writes that is trying to get the console, controller accordingly nobody bothers me. - pearl_Web commented on October 3rd 19 at 03:12
:) - Braden.Langwor commented on October 3rd 19 at 03:15
October 3rd 19 at 03:11
what version of rails? if 3, you may need to add another Customer in
attr_accessible :contractor_id
Thanks for the response, rails 4E. You don't know how to do them? - pearl_Web commented on October 3rd 19 at 03:14
October 3rd 19 at 03:13
replace
has_many :contractorEs

on
has_many :contractors


and you will be happy
Please explain more, what does it mean? Why –°ontractor have a lot –°ontractor-s? contratorEs is a different type altogether. Something I don't understand. - pearl_Web commented on October 3rd 19 at 03:16
I misread the problem.

you wrote that you are using STI, that is, there is only one users table and the field you added to the customers table. - Braden.Langwor commented on October 3rd 19 at 03:19
October 3rd 19 at 03:15
try to make has_many :through Association, http://www.rusrails.ru/active-record-associations, and during the migrations it is better to use contactor:references:index

Find more questions by tags RubyActive RecordRuby on Rails