Wednesday, April 28, 2010

[Rails] .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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate