Skip to content

Instantly share code, notes, and snippets.

View csm123's full-sized avatar

Corey Martin csm123

View GitHub Profile
@csm123
csm123 / create_or_update_unique.rb
Created March 28, 2021 20:48
create_or_update_unique method for Rails
# A utility method for idempotent writes with ActiveRecord.
# Add a unique Postgres or MySQL index for the fields in `unique_attributes`.
# The method will look attempt to create a record. If it fails due to a
# unique index validation, it will update the existing record with the same
# unique attributes.
# Inpired by `create_or_find_by` in Rails 6, but serves a different use case.
# https://bigbinary.com/blog/rails-6-adds-create_or_find_by
class CreateOrUpdateUnique
@csm123
csm123 / index.html.haml
Last active April 12, 2017 07:56
React/Fluxxor in Rails Example
:javascript
$(document).ready(function() {
window.loadIngredientSuggestionsEditor(#{@ingredients});
});
%h1 Edit ingredient suggestions
#js-ingredient-suggestions-editor