1
0
Fork 0

Add attribute Account#guest_token

This commit is contained in:
Alex Kotov 2018-12-10 07:52:34 +05:00
parent 6beeb86f40
commit 71cc678151
No known key found for this signature in database
GPG Key ID: 4E831250F47DE154
3 changed files with 15 additions and 1 deletions

View File

@ -13,6 +13,10 @@ class Account < ApplicationRecord
scope :guests, -> { includes(:user).where(users: { id: nil }) }
before_create do
self.guest_token = SecureRandom.hex
end
def guest?
user.nil?
end

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
class AddGuestTokenToAccounts < ActiveRecord::Migration[5.2]
def change
add_column :accounts, :guest_token, :string,
null: false, # rubocop:disable Rails/NotNullColumn
index: { unique: true }
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2018_12_07_030332) do
ActiveRecord::Schema.define(version: 2018_12_10_024922) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -28,6 +28,7 @@ ActiveRecord::Schema.define(version: 2018_12_07_030332) do
create_table "accounts", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "guest_token", null: false
end
create_table "active_storage_attachments", force: :cascade do |t|