# Create! Syntax

**URL:** <https://www.ruby-forum.com/t/create-syntax/174020>\
**Category:** Rails\
**Created:** [August 19, 2009, 4:01pm UTC](https://www.ruby-forum.com/t/create-syntax/174020 "2009-08-19T16:01:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e99b99/32.png) [@chero](https://www.ruby-forum.com/u/chero)\
**Post date:** [August 19, 2009, 4:01pm UTC](https://www.ruby-forum.com/t/create-syntax/174020/1 "2009-08-19T16:01:16Z")

</div>

Hey All,

Two questions.

Firstly, what is the difference between create and create!

I see that create is document in the api

> **[ActiveRecord::Base](https://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002269)**
>
> Active Record Active Record objects don't specify their attributes directly, but rather infer them from the table definition with which they're linked.

What is the difference between the two of these functions and where is  
the  
create! function defined.

Also,

What are the differences between these two calls?

a) SomeModel.create!{ :property\_a =\> ‘value’, :property\_b =\> ‘value 2’  
}  
b) SomeModel.create!({ :property\_a =\> ‘value’, :property\_b =\> ‘value  
2’ })

Thanks a lot for the help!  
-Jim

---

<div class="post-metadata">

**Author:** ![chero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e99b99/32.png) [@chero](https://www.ruby-forum.com/u/chero)\
**Post date:** [August 19, 2009, 4:36pm UTC](https://www.ruby-forum.com/t/create-syntax/174020/2 "2009-08-19T16:36:23Z")

</div>

On Aug 19, 10:00 am, James E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What is the difference between the two of these functions and where is the  
> -Jim  
> create! is here:

[http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html](http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html)

I find [http://railsapi.com](http://railsapi.com) to be the best tool for browsing the Rails  
documentation.

---

<div class="post-metadata">

**Author:** ![chero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e99b99/32.png) [@chero](https://www.ruby-forum.com/u/chero)\
**Post date:** [August 19, 2009, 10:20pm UTC](https://www.ruby-forum.com/t/create-syntax/174020/3 "2009-08-19T22:20:33Z")

</div>

James E. wrote:

> Hey All,
> 
> Two questions.
> 
> Firstly, what is the difference between create and create!

create returns true if successful, false otherwise. create! throws an  
exception if the operation fails for any reason.

> What are the differences between these two calls?
> 
> a) SomeModel.create!{ :property\_a =\> ‘value’, :property\_b =\> ‘value 2’  
> }  
> b) SomeModel.create!({ :property\_a =\> ‘value’, :property\_b =\> ‘value  
> 2’ })

Nothing. The {} indicating the hash is optional if it’s obvious to the  
Ruby interpreter. If you were to have two hash arguments you need to  
separate them properly so the interpreter understand what to do:

do\_this({ :a =\> ‘a’, :b =\> ‘b’ }, { :c =\> ‘c’, :d =\> ‘d’ })

See if the braces aren’t present then it would look like:

do\_this(:a =\> ‘a’, :b =\> ‘b’ , :c =\> ‘c’, :d =\> ‘d’)

Which is probably not what you want if you intended to send two hashes  
to the method. In the second case there is only one hash send and the  
second argument would not be set.

It might do you some good to go back and brush up your basic Ruby  
skillz.
