update_attribute on a specific record

5 views
Skip to first unread message

abenego

unread,
Feb 10, 2012, 5:30:24 AM2/10/12
to Ruby on Rails: Talk
Newbie alert! :)

Guys, I am trying to update a record on the console (Heroku)
I have an object called Photo
Photos have a tittle,... how do I address an specific photo via it's
Id if I want to
update the tittle description etc?


Any help will be great.

Walter Lee Davis

unread,
Feb 10, 2012, 2:56:23 PM2/10/12
to rubyonra...@googlegroups.com

If you know the ID, then you can do this:

photo = Photo.find 123
photo.title = 'A greater title than before'
photo.save

Walter

> Any help will be great.
>

> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>

Linus Pettersson

unread,
Feb 10, 2012, 3:39:22 PM2/10/12
to rubyonra...@googlegroups.com
Yep, or:
Photo.find(123).update_attribute(:title => "New great title")

Regards
Reply all
Reply to author
Forward
0 new messages