Elliot Theis

  • Random
  • Archive
  • RSS
  • Ask me anything

Rails new vs build

@article = Article.new

Creates a new instance of a Model.

@comment = @article.comments.build

Just like the new method, but by assocation proxies (not for Models). It automatically sets the foreign_key.

The other thing is that when you are doing a “has_one” the build looks like this:

@comment = @article.build_comment

    • #tip
    • #rails
    • #quick tips
  • 7 months ago
  • 21
  • Permalink
  • Share
    Tweet

21 Notes/ Hide

  1. elliottheis posted this
← Previous • Next →

Portrait/Logo

About

I'm an entrepreneur, consultant, and rails developer who is keen to make his mark in the world.

Pages

  • About Me
  • CrunchBase
  • LinkedIn

Me, Elsewhere

  • @elliottheis on Twitter
  • elliottheis on Foursquare
  • My Skype Info
  • Linkedin Profile

Twitter

loading tweets…

  • RSS
  • Random
  • Archive
  • Ask me anything
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr