Ruby on rails 导轨,Cequel-Don和#x27;我不知道如何对UUID进行强制转换
我正在学习本教程(),但在登录时遇到了问题。当我收到以下错误时:Ruby on rails 导轨,Cequel-Don和#x27;我不知道如何对UUID进行强制转换,ruby-on-rails,devise,cequel,Ruby On Rails,Devise,Cequel,我正在学习本教程(),但在登录时遇到了问题。当我收到以下错误时: HomeController#索引中的参数错误 不知道如何将{“n”=>242893962554067921677178635377202198460}强制转换为UUID 提取的源(第423行附近): Deave使用的模型为: class User include Cequel::Record devise :database_authenticatable, :registerable key :id, :u
HomeController#索引中的参数错误 不知道如何将{“n”=>242893962554067921677178635377202198460}强制转换为UUID 提取的源(第423行附近):
Deave使用的模型为:
class User
include Cequel::Record
devise :database_authenticatable, :registerable
key :id, :uuid, auto => true
column :username, :varchar, :index => true
column :name, :varchar
column :lastname, :varchar
column :email, :varchar, :index => true
column :encrypted_password, :varchar
timestamps
end
如果我将密钥更改为varchar,它可以工作,但我不想使用UUID,这样用户就可以更改电子邮件或其用户名
如何更正它?如果您查看方法源
uuid
,您将看到:
这意味着在它处,假设像nil
,Time
,DateTime
这样的值。在其中任何一种情况下,它都不会使用位于以下位置的::Timeuuid类型的方法cast
任何cast
方法定义似乎都没有等待接收hash
作为一种解决方法,您可以尝试类似于Cql::Uuid.new(值['n'])
但是你应该检查一下为什么会有一个散列,它到底应该是什么似乎我对cequel+devise做了一些错事,我不喜欢uuid作为用户密钥。使用varchar是正确的。
class User
include Cequel::Record
devise :database_authenticatable, :registerable
key :id, :uuid, auto => true
column :username, :varchar, :index => true
column :name, :varchar
column :lastname, :varchar
column :email, :varchar, :index => true
column :encrypted_password, :varchar
timestamps
end
def uuid(value = nil)
if value.nil?
timeuuid_generator.now
elsif value.is_a?(Time)
timeuuid_generator.at(value)
elsif value.is_a?(DateTime)
timeuuid_generator.at(Time.at(value.to_f))
else
Type::Timeuuid.instance.cast(value)
end
end