What is the difference build and new?

What is the difference between

parent.children << child.new

and

parent.children.build(params[:child])

2010/4/23 Manoj K. [email protected]:

What is the difference between

parent.children << child.new

and

parent.children.build(params[:child])

What is the question? Seriously you do not provide any information
about context or what code you are presenting. How do you expect us
to answer such a question?

Regards

robert

Robert K. wrote:

2010/4/23 Manoj K. [email protected]:

What is the difference between

parent.children << child.new

and

parent.children.build(params[:child])

What is the question? Seriously you do not provide any information
about context or what code you are presenting. How do you expect us
to answer such a question?

At a guess, it’s an ActiveRecord question.

ActiveRecord is a component of Rails. If you have a question on Rails,
please use a Rails mailing list. I’m sure it’s not intentional, but it’s
rather rude to post a question about one subject (Rails) on a mailing
list devoted to another (Ruby).

Rails is not Ruby - it’s an application framework which just happens to
be written in Ruby.

Thanks Luis…

On Apr 23, 4:34 am, Manoj K. [email protected] wrote:

What is the difference between

parent.children << child.new

and

parent.children.build(params[:child])

Under has_many examples, build is used to automatically fill up the
relationship data. The documentation is your friend, spend some time
reading it.

Now that I’ve google that for you, another useful link:

Post your Ruby on Rails related questions there in the Rails mailing
lists, not here as there are better chances you don’t get any answer
at all since this list is mainly Ruby.