Rails

Using Build Or New On A Has_one Assoication In Rails

Posted by Weston Ganger on May 05, 2015

If you need to use build or new on a has_one association, its a little different then the has_many.


# has_many, this will throw errors on a has_one
@post.comments.build
# OR
@post.comments.new

# on a has_one association
@post.build_comment


Related External Links:


Posted in Rails and Tagged with rails associations has_one 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts