.build for has_one

I am having problems understanding this concept.

I am guessing that, for has_one/belongs_to one should use something
different from .build.

for example,
if I have the following
class Student < ActiveRecord::Base
has_many :notes
end

class Note < ActiveRecord::Base
belongs_to :students
end

Then

def new
@student = Student.new
@student.notes.build
end


But when I have the following association :

class Student < ActiveRecord::Base
has_one :econtact
end

class Econtact < ActiveRecord::Base
belongs_to :student
end

then
def new
@student = Student.new
@student.build_econtact
end

I am trying the latter, and it does not build the record with the
association.

Can someone help, please
Thanks
-Luis

Hi

You have to read
http://guides.rubyonrails.org/association_basics.html
especially sections 4.1.1.3 , 4.2.1.3 and 4.3.1.12

Sijo

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs