Add attribute Account#guest_token
This commit is contained in:
parent
6beeb86f40
commit
71cc678151
|
@ -13,6 +13,10 @@ class Account < ApplicationRecord
|
||||||
|
|
||||||
scope :guests, -> { includes(:user).where(users: { id: nil }) }
|
scope :guests, -> { includes(:user).where(users: { id: nil }) }
|
||||||
|
|
||||||
|
before_create do
|
||||||
|
self.guest_token = SecureRandom.hex
|
||||||
|
end
|
||||||
|
|
||||||
def guest?
|
def guest?
|
||||||
user.nil?
|
user.nil?
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -28,6 +28,7 @@ ActiveRecord::Schema.define(version: 2018_12_07_030332) do
|
||||||
create_table "accounts", force: :cascade do |t|
|
create_table "accounts", force: :cascade do |t|
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.string "guest_token", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "active_storage_attachments", force: :cascade do |t|
|
create_table "active_storage_attachments", force: :cascade do |t|
|
||||||
|
|
Reference in New Issue