Skip to content

Instantly share code, notes, and snippets.

@eirvandelden
Last active August 18, 2022 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eirvandelden/172548c72aff03181418c2c04516ebd5 to your computer and use it in GitHub Desktop.
Save eirvandelden/172548c72aff03181418c2c04516ebd5 to your computer and use it in GitHub Desktop.
unknown attribute 'guid' for NfcTag. raise
class CreateNfcTags < ActiveRecord::Migration[6.1]
def change
create_table :nfc_tags do |t|
t.string :guid
t.integer :number
t.timestamps
end
end
end
require "rubygems"
require "bundler"
Bundler.require
require "sinatra"
require "securerandom"
require "sinatra/activerecord"
require "debug"
set :database, { adapter: "sqlite3", database: "nfc_writer_helper.sqlite3" }
class NfcTag < ActiveRecord::Base
end
get "/:number" do
begin
tag = NfcTag.find number: params[:number]
rescue ActiveRecord::RecordNotFound
tag = NfcTag.create guid: SecureRandom.uuid, number: params[:number].to_i
end
"https://MY_URL.TEST/id/#{tag.guid}/?nfc_number=#{tag.number}"
end
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_08_16_124058) do
create_table "nfc_tags", force: :cascade do |t|
t.string "guid"
t.integer "number"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment