This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
Note: params[:widget_id] does have a value of 0 (zero) when I want to generate a new record vs an actual value when doing an edit. This is a non-standard rails form, I did not experience any issues with a standard new/create view/action scenario.