Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Elliott Geier
Elliott Geier
10,169 Points

Adding uuid's to a table in my rails app.

I am currently writing an application that will create a blank photo object with only a uuid and creation date as a skeleton for when an actually photo is added to the object. However I am having trouble finding any information about uuid's on the internet. If anyone can lead me in the right direction would be appreciated.

I have already set my primary-key to uuid.. but when I use rails console and create a new picture object the uuid is not generated instead the default shows.

irb(main):007:0> Picture.create (0.0ms) begin transaction (0.0ms) rollback transaction => #<Picture id: nil, created_at: nil, updated_at: nil, uuid: "uuid_generate_v4()">


ActiveRecord::Schema.define(version: 20170307152118) do

create_table "photo_booths", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "booth_number" t.string "booth_location" t.integer "picture_count" end

create_table "pictures", id: nil, force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false t. "uuid", default: "uuid_generate_v4()", null: false <--------------- t.index ["id"], name: "sqlite_autoindex_pictures_1", unique: true end

end

module Photobooth class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. config.generators do |generator| generator.orm :active_record, primary_key_type: :uuid <---------------- end end end

I have been stuck for a few hours now.. but I am new and dont know where to go