Skip to content

Instantly share code, notes, and snippets.

@deep-spaced
Last active December 15, 2015 03:05
Show Gist options
  • Save deep-spaced/87f94478562de0794397 to your computer and use it in GitHub Desktop.
Save deep-spaced/87f94478562de0794397 to your computer and use it in GitHub Desktop.
Ruby Boolean logic
return Photo.find(params[:photo][:id]) or Photo.new
# Valid parameter: instance from database
# Invalid parameter: new instance
return photo = Photo.find(params[:photo][:id]) and photo.update(comment: params[:photo][:comment]) and photo
# Valid ID and successful update: photo instance
# Valid ID and failed update: result of update
# Invalid ID: nil
# Yes, I work in Rails. You got a problem with that?!?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment