I am a bit confused, how works include.
I have this query to database: @car = Car.includes(:colors).paginate(:per_page => 10, :page => params[:page])
In table Car I have columns: name, price, color, …
In table Colors columns: car_id, name, color_name, …
In my view I can use for printing price of the car @car.price, but I can’t use @car.color_name, why?
And the another problem – I have in both tables the column called have, how I will to know, with which one I am working currently? If I will do @car.name, so this value will be take from Cars table or Colors?
I am sorry for maybe stupid question, but I don’t know, how to work with the data from 2 tables.
Assuming that this is a Car
has_manyColors association it will look something like this:When you use the
includesstatement, this does not mean both models are mixed into each other. The associations are just preloaded, but the common rails association structure is still the same… Hope this helps 🙂