Skip to content

Instantly share code, notes, and snippets.

@luxxi
luxxi / application_controller.rb
Created April 5, 2015 20:40
Can't verify CSRF token authenticity
class ApplicationController < ActionController::Base
protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' }
end
@luxxi
luxxi / update_or_create.rb
Last active August 29, 2015 14:17
update_or_create
#Using in single model
def self.update_or_create(attributes)
obj = first || new
obj.assign_attributes(attributes)
obj
end
#User.where(email: "a@b.com").update_or_create(email: "d@e.com")