Update a single record’s attribute

Need to update a single record’s attribute? This will allow you to update a single attribute and save your record. If you use this method, you will also bypass any validation…beware, attributes can be updated even if the object is invalid. 

# find the first Condo
# update the flagged column with the params

current_condo = Condo.find(:first)
current_condo.update_attribute(:flagged, params[:submission][:flagged])

# find the the condo by permalink
# set the condo.name and condo.zipcode
# save

condo = Condo.find_by_permalink("114-pike-street-condos")
condo.name = "114 Pike Street Condos"
condo.zipcode = "98105"
condo.save!

Tags: , ,

3 comments

  1. Thanks, found this useful.

  2. cool,.tnx..^^

  3. cool,.tnx..^^

Leave a comment