Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7067121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:09:47+00:00 2026-05-28T05:09:47+00:00

I’m working with the UUIDTools gem in Rails 3 and running into some problems.

  • 0

I’m working with the UUIDTools gem in Rails 3 and running into some problems. It seems to work fine in practice:

> item = Item.create
 => #<Item uuid: "e9d00043-9200-4497-a55c-509c5de3dd88", created_at: "2012-01-09 01:56:49", updated_at: "2012-01-09 01:56:49">
> item.id
 => "e9d00043-9200-4497-a55c-509c5de3dd88"

But then in my specs it tells a different story:

require 'spec_helper'
describe Item do
  it 'should assign an id' do
    item = Item.create
    puts "item id: #{item.id}"
  end
end

Running this spec shows:

item id: 5
.

Finished in 2.21 seconds
1 example, 0 failures

Where’s my guid? There doesn’t seem to be any pattern to what id is assigned, I’ve run this a bunch of times and seen it go anywhere from 0 to up in the thousands.

Here is my migration:

class CreateItems < ActiveRecord::Migration
  def change
    create_table :items, :id => false do |t|
      t.string :uuid, :null => false, :primary => true

      t.timestamps
    end

    add_index :items, :uuid, :unique => true
  end
end

My model:

require 'uuid_helper'

class Item < ActiveRecord::Base
  include UUIDHelper
end

And my uuid_helper:

module UUIDHelper
  def self.included(base)
    base.class_eval do
      set_primary_key :uuid
      attr_readonly :uuid
      before_create :set_uuid

      private

      def set_uuid
        self.uuid = UUIDTools::UUID.random_create.to_s
      end
    end
  end
end

Putting some debugger logic into set_uuid I’ve discovered that it’s doing to_i on the uuid at some point. Any suggestions?

Update This seems to be a bug in the Rails test environment. When I run RAILS_ENV=test rails console I get the same behavior as in the specs–the guids are chopped off.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:09:47+00:00Added an answer on May 28, 2026 at 5:09 am

    Alright, the answer was to upgrade to Rails 3.1.3 from 3.1.1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.