ruby on rails- nested attributes for 'has_one' relationship

Posted by Kum on Stack Overflow See other posts from Stack Overflow or by Kum
Published on 2011-01-17T14:48:47Z Indexed on 2011/01/17 14:53 UTC
Read the original article Hit count: 115

Filed under:

Hello,

I need some help concerning nested attributes in models with 'has_one' relationship.

Model Survey has 1 question Model Question has 1 answer

How do i build the 'answer' in the code below

def new
  @survey = Survey.new
   @survey.build_question # build one question
    @survey.question.answer.build #this part is not working

end

Please can anybody tell me how to build the answer as the code "@survey.question.answer.build" is not correct.

Many many thanks for your help

© Stack Overflow or respective owner

Related posts about ruby-on-rails