Skip to content

Instantly share code, notes, and snippets.

@staycreativedesign
Created June 15, 2017 15:58
Show Gist options
  • Select an option

  • Save staycreativedesign/9dc57e2ecc44e4b719e4f28d326ea063 to your computer and use it in GitHub Desktop.

Select an option

Save staycreativedesign/9dc57e2ecc44e4b719e4f28d326ea063 to your computer and use it in GitHub Desktop.
class CreatePrivateRooms < ActiveRecord::Migration[5.0]
def change
create_table :private_rooms do |t|
t.timestamps
t.string :name
end
end
end
Loading development environment (Rails 5.0.2)
2.4.1 :001 > PrivateRoom.create
(0.2ms) BEGIN
SQL (1.3ms) INSERT INTO "private_rooms" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id" [["created_at", 2017-06-15 15:58:13 UTC], ["updated_at", 2017-06-15 15:58:13 UTC]]
(1.0ms) COMMIT
=> #<PrivateRoom id: 2, created_at: "2017-06-15 15:58:13", updated_at: "2017-06-15 15:58:13", name: nil>
class PrivateRoom < ApplicationRecord
before_create :generate_link
def to_params
binding.pry
self.name
end
private
def generate_link
binding.pry
self.name = SecureRandom.hex(8).to_s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment