Skip to content

Instantly share code, notes, and snippets.

@GiancarlosIO
Last active July 28, 2016 03:57
Show Gist options
  • Save GiancarlosIO/4ecb7674260ed0910b05f1ac323311df to your computer and use it in GitHub Desktop.
Save GiancarlosIO/4ecb7674260ed0910b05f1ac323311df to your computer and use it in GitHub Desktop.
# my_api/app/models/user.rb
class User < ActiveRecord::Base
validates :email, presence: true, uniqueness: true
validates :name, presence: true
def self.with_token(data)
User.where(email: data[:email]).first_or_create do |user|
user.email = data[:email]
user.name = data[:name]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment