Forum: Ruby on Rails help on has_one

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
8a7f4310211e0dd831388455f5588b97?d=identicon&s=25 pantouffe (Guest)
on 2007-01-19 18:03
(Received via mailing list)
I'm having:
   colour model with id,name,value
   car model, id,name,colour_id
   chair model id,name,colour_id
- i have a many to one relation, correct? - different type of objects
have a colour.
putting for the car and chair model an attribute has_one :colour, is't
enough. I thought that having:

class Car<ActiveRecord::Base
  has_one :colour
  def before_create()
    colour = = 'red'

 when I would create a Car object and save-it i should have in the
database for that record color_id <> 0, but
i found that it is NULL.
-what did I do wrong?
This topic is locked and can not be replied to.