# Bug or Feature / @var.save

**URL:** <https://www.ruby-forum.com/t/bug-or-feature-var-save/104415>\
**Category:** Rails\
**Created:** [May 17, 2007, 6:29pm UTC](https://www.ruby-forum.com/t/bug-or-feature-var-save/104415 "2007-05-17T18:29:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 17, 2007, 6:29pm UTC](https://www.ruby-forum.com/t/bug-or-feature-var-save/104415/1 "2007-05-17T18:29:10Z")

</div>

Hi all,

I have just a little problem. I want to save an object back to my  
database table.

if I do itlike that:

e = Event.new(params)  
e.save!

e.id returns the correct id of the created db entry

however if I do it like that.

e = Event.new(params).save!

e is just true (which is correct, but I hoped I’ll get back the object)

Can you tell, I am still not very familiar with Ruby :-/

How can I do this in one line?  
Thanks for a hint  
Karl

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 17, 2007, 6:43pm UTC](https://www.ruby-forum.com/t/bug-or-feature-var-save/104415/2 "2007-05-17T18:43:14Z")

</div>

On 5/17/07, km [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> e.id returns the correct id of the created db entry
> 
> however if I do it like that.
> 
> e = Event.new(params).save!

You’re setting e to the return value of save! You can use create!  
though:

e = Event.create!(params)

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 17, 2007, 6:44pm UTC](https://www.ruby-forum.com/t/bug-or-feature-var-save/104415/3 "2007-05-17T18:44:14Z")

</div>

On Thu, May 17, 2007 at 06:29:10PM +0200, km wrote:

> e.id returns the correct id of the created db entry
> 
> however if I do it like that.
> 
> e = Event.new(params).save!
> 
> e is just true (which is correct, but I hoped I’ll get back the object)
> 
> Can you tell, I am still not very familiar with Ruby :-/

Yes, I can tell. You will find using Rails much easier and more  
productive  
if you actually know Ruby. Go learn it.

> How can I do this in one line?

(e = Event.new(params)).save!

> Thanks for a hint  
> Karl  
> –Greg
