Bug or Feature / @var.save

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

On 5/17/07, km [email protected] 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://weblog.techno-weenie.net
http://mephistoblog.com

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs