Skip to content

Instantly share code, notes, and snippets.

@house9
Created April 25, 2009 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save house9/101669 to your computer and use it in GitHub Desktop.
Save house9/101669 to your computer and use it in GitHub Desktop.
# this worked as expected on mysql
# on postgresql it created a new widget with id of 0
def some_method
widget = Widget.find_or_initialize_by_id(params[:widget_id])
# ...
end
# workaround code for postgresql
def some_method
widget = Widget.find_or_initialize_by_id(params[:widget_id])
widget = Widget.new if widget.id == 0
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment