gpt4 book ai didi

ruby-on-rails - postgres 9.4,pgcrypto 0.4.1,rails 4.2.0,ruby 2.2.0,引用预期的字符串,得到 Arel::Nodes::BindParam

转载 作者:行者123 更新时间:2023-11-29 13:28:26 25 4
gpt4 key购买 nike

尝试创建加密列时出现问题。 OS X 10.9.5

使用 gnupg 2.0.22 创建公钥/私钥:

    gpg -a --export > myKey .key.pub
gpg -a --export-secret-key myKey > .key.prv

关于这里可能发生的事情的任何指示?我有一个带有 ssn 字段的模型迁移添加为:

    add_column :users, :ssn, :binary

在用户模型中

    has_encrypted_column :ssn

为开发数据库添加了 pgcrpyto 扩展

在 config/initializers/pgcrypto.rb

    PGCrypto.keys[.public] = {path: '.key.pub'}
PGCrypto.keys[.private] = {path: '.key.prv',armored: true, password: 'myPassword'}

rails c

    User.create(username:'x',ssn:'123-45-6789')

得到这个错误,column is ssn so it looks like it doing the right thing

TypeError: wrong argument type Arel::Nodes::BindParam (expected String)
from ... /vendor/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql/quoting.rb:19:in `escape_string'
from ... /vendor/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql/quoting.rb:19:in `quote_string'
from ... /vendor/ruby/2.2.0/gems/pgcrypto-0.4.1/lib/pgcrypto/adapter.rb:51:in `pgcrypto_encrypt_string'

下面的 **** 是我认为错误所在但不确定在这里调用什么方法的地方:找不到很多关于 Arel::Nodes::BindParam 的文档。我假设这应该将值设置为“123-45-6789”,然后使用 pgcrypto_encrypt_string 调用对其进行加密。我验证了 key 是正确的。

     57     def pgcrypto_insert(arel)
58 if table = PGCrypto[arel.ast.relation.name.to_s]
59 arel.ast.columns.each_with_index do |column, i|
60 if options = table[column.name.to_sym]
61 key = options[:key] || PGCrypto.keys[:public]
62 next unless key
63 # Encrypt encryptable columns
64 ***** value = arel.ast.values.expressions[i]
65 arel.ast.values.expressions[i] = pgcrypto_encrypt_string(value, key)
66 end
67 end
68 end
69 end

非常感谢任何指点。弄清楚后很高兴 fork 并提出拉取请求。

最佳答案

猜测是由于 Rails 4.2.0 中的 Arel 6.0

在 rails 4.1.0、Arel 5.0 中

    Arel::Nodes::BindParams < Arel::Nodes::SqlLiteral < String < Object < BasicObject

在 rails 4.2.0 Arel 6.0 中

    Arel::Nodes::BindParams < Arel::Nodes::Node < Object < BasicObject

有关如何从 Arel::Nodes::Node 中提取值的任何提示

关于ruby-on-rails - postgres 9.4,pgcrypto 0.4.1,rails 4.2.0,ruby 2.2.0,引用预期的字符串,得到 Arel::Nodes::BindParam,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29102190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com