I’m trying to be a good rails developer and fix DRY violations as i find
them. However, i’m trying to fix this one, i cant seem to get it to
I have two tables A and B that have a one-to-one relationship. Table B
belongs_to Table A. Table A has_one Table B. I’m creating instances of
Table A in different places, depending on the controller. However, for
time i create a Table A instance, i also need to create an empty Table B
I tried to incorporate this into the model for Table A using various
callbacks, after_create, after_save, before_create. Trying to set the
table_b attribute to a new Table B instance and have table_b’s foreign
be the id the table_a object being created.
However, i kept running into exceptions "undefined method
I checked my dev log and saw there was an INSERT query for table_b just
after table_a’s INSERT, which is what i wanted. But it dies right
Why is that?
So do i need to just call
table_a_inst.table_b = Table_B.new()
everytime i want to create a Table_A instance?
thanks in advance.