Skip to content

Instantly share code, notes, and snippets.

@rolentle
Created January 20, 2014 04:24

Revisions

  1. rolentle created this gist Jan 20, 2014.
    29 changes: 29 additions & 0 deletions user.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    class User < ActiveRecord::Base

    has_many :trips
    has_many :feed_sources
    has_many :photos
    has_many :statuses
    has_many :checkins
    validates :name, :presence => true

    def possessive_name
    name.ends_with?("s") ? name + "'" : name + "'s"
    end

    def self.from_omniauth(auth)
    user = User.find_or_create_by(
    name: auth["info"]["nickname"]
    )

    user.update_attributes(
    uid: auth["uid"],
    provider: auth["provider"],
    avatar_url: auth["info"]["image"],
    access_token: auth["credentials"]["token"],
    access_secret: auth["credentials"]["secret"]
    )

    user
    end
    end