相关疑难解决方法(0)

Rails3中的UUID

我正在尝试设置我的第一个Rails3项目,在早期,我遇到了问题,无论是uuidtools我的UUIDHelper还是回调.我显然正在尝试使用UUID和(我认为)我按照Ariejan de Vroom的文章中所描述的那样进行了设置.我已经尝试使用UUID作为主键,也只是一个补充字段,但似乎UUIDHelper永远不会被调用.

我已经阅读了许多关于Rails3中回调和/或帮助器改变的提及,但我找不到任何可以告诉我如何调整的细节.这是我现在的设置(已经进行了几次迭代):

# migration
class CreateImages < ActiveRecord::Migration
  def self.up
    create_table :images do |t|
      t.string :uuid, :limit  => 36
      t.string :title
      t.text :description

      t.timestamps
    end
  end
  ...
end

# lib/uuid_helper.rb
require 'rubygems'
require 'uuidtools'

module UUIDHelper
  def before_create()
    self.uuid = UUID.timestamp_create.to_s
  end
end

# models/image.rb
class Image < ActiveRecord::Base
  include UUIDHelper

  ...
end
Run Code Online (Sandbox Code Playgroud)

任何见解都会非常感激.

谢谢.

ruby-on-rails

7
推荐指数
2
解决办法
1万
查看次数

Is COMB GUID a good idea with Rails 3.1 if I use GUIDs for primary keys?

I'm using Rails 3.1 with PostgreSQL 8.4. Let's assume I want/need to use GUID primary keys. One potential drawback is index fragmentation. In MS SQL, a recommended solution for that is to use special sequential GUIDs. One approach to sequential GUIDs is the COMBination GUID that substitutes a 6-byte timestamp for the MAC address portion at the end of the GUID. This has some mainstream adoption: COMBs are available natively in NHibernate (NHibernate/Id/GuidCombGenerator.cs).

I think I've figured out …

uuid activerecord guid ruby-on-rails ruby-on-rails-3.1

4
推荐指数
1
解决办法
1467
查看次数