Ruby on Rails Monday, April 1, 2019

The `build` method constructs the ORM object without validating or saving. It provides an opportunity to configure attributes before saving, before validating. If you feel good about the `params[:auction]`, have them filtered with `require` and `permit`, and aren't going to groom the record any further, then `create` or `create!` will serve. When using `create` it's necessary to check the return value for failures. With `create!` you'll have the `ActiveRecord::RecordInvalid` or other exception to capture on failure.

On Sunday, March 31, 2019 at 6:39:40 PM UTC-3, fugee ohu wrote:
I can create a new record from the model on the right side of a has_many statement Why user the model on the left plus . plus the model on the right plus build The reason I'm asking is because I came across this piece of code below As you can see it's a little primitive placing the seller's name in the auction model instead of leaving it alone and rendering in views from the records in User I'm gonna remove seller_name from the table

   @auction = current_user.auctions.build(params[:auction])
    @auction.seller_name = current_user.name

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b8c64601-a5f9-445d-ba1d-f1e8c2b0b8c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment