所以我有一个我正在开发的rails应用程序,它是Stripe的订阅服务。创建用户时,会为他们分配一个:id,然后在他们购买订阅时获得:id。
他们的帐户信息的路径,因为它的Stripe看起来像这样的东西真的不多了: https://myappnamehere.herokuapp.com/koudoku/users/47/subscriptions/2
这是第47个用户,也是第3个用户。
我的问题是
感谢您的见解!
答案 0 :(得分:1)
从控制台运行
rails generate migration enable_uuid_ossp_extension
rails generate model document title:string author:string
然后编辑您的迁移,如下所示:
class EnableUuidOsspExtension < ActiveRecord::Migration
def change
enable_extension 'uuid-ossp'
end
end
然后编辑相关的模型迁移或创建更改迁移以使您的模型使用新的UUID
class CreateDocuments < ActiveRecord::Migration
def change
create_table :documents, id: :uuid do |t|
t.string :title
t.string :author
t.timestamps
end
end
end
然后运行:
rake db:create
rake db:migrate
现在你应该好好去。要记住的一件事是,为了使.first和.last方法起作用,您必须创建自己的范围以使用created_at时间戳执行查询。