简体   繁体   English

入门:Ruby,Rails,UUID

[英]Getting Started: Ruby, Rails, UUIDs

There seems to be no shortage of questions out there about this, but it's a little more difficult to find solid answers that aren't woefully out of date. 关于这一点似乎并不缺乏任何问题,但要找到并非过时的可靠答案会更加困难。 I'm taking my first (baby) steps with Rails (and Ruby, for that matter) and I'd really like to use UUIDs as my primary key. 我正在使用Rails(以及Ruby)的第一步(婴儿)步骤,我真的想使用UUID作为我的主键。 In fact, for most of my projects, it's all but essential since I frequently have to move chunks of data between one database and another. 实际上,对于我的大多数项目来说,这几乎是必不可少的,因为我经常需要在一个数据库和另一个数据库之间移动数据块。

As far as I can tell, Rails has no native means of handling this need. 据我所知,Rails没有处理这种需求的本地方法。 I'm running Ruby 1.8.6 and Rails 2.3.3. 我正在运行Ruby 1.8.6和Rails 2.3.3。 Am I missing something? 我错过了什么吗? Is there a later version that might offer this capability? 是否有可能提供此功能的更高版本? Is it perhaps on the roadmap somewhere? 它可能在某个地方的路线图上吗? Is there any other way to provide this capability? 有没有其他方法可以提供此功能? Rails is pretty much a non-starter for me (beyond the academic) without UUID support. 在没有UUID支持的情况下,Rails对我来说(在学术界之外)几乎不是首发。

Being new to Ruby and Rails, I'm still learning all of the right places to look for info/answers so I may be too quick in asking this question here. 作为Ruby和Rails的新手,我仍然在学习寻找信息/答案的所有合适的地方,所以我可能会在这里提出这个问题。 Nonetheless, any insight I can get would be much appreciated. 尽管如此,我能得到的任何见解都会非常感激。

Thanks. 谢谢。

I don't know much about UUIDs but a quick google search yields the following: 我不太了解UUID,但快速谷歌搜索产生以下结果:

Ruby on Rails: UUID as your ActiveRecord primary key - Ariejan.net Ruby on Rails:UUID作为您的ActiveRecord主键 - Ariejan.net

Try installing the UUIDTools gem and give it a whirl. 尝试安装UUIDTools宝石并给它一个旋转。

Cheers. 干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM