使用attr_encrypted用铁轨7
我们已将应用程序升级为Rails 7,现在我们对Attr_encrypted Gem有问题。当我们尝试启动Rails服务器/控制台时,我们会收到以下错误:
gems/ruby-3.0.2/gems/attr_encrypted-3.1.0/lib/attr_encrypted.rb:176:in `block in attr_encrypted': undefined method `[]=' for nil:NilClass (NoMethodError)
如果回到Rails 6,错误消失了,是否有人遇到了同样的问题?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
所以我终于弄清楚了发生了什么。
Rails 7.0具有其自身的加密,Attr_encrypted Gem和Rails 7是指变量
gencrypted_attributes
,而Rails 7变量则优先考虑,使Gem无用。 Attr_encrypted Gem上有一个PR可以解决此问题,但是GEM已多年没有更新,我怀疑现在会这样。Gorails发布了一个教程,有关如何将数据从使用attr_encrypted迁移到使用Rails 7加密的教程。我不想付钱,所以我检查了该教程的GIT回购。
他们所做的是在迁移中解密数据并手动更新了新的加密字段。
这是他们迁移的链接。
So I have finally figured out what's going on.
Rails 7.0 has it's own encryption, both the attr_encrypted gem and rails 7 refer to the variable
encrypted_attributes
and the rails 7 variable takes precedence making the gem useless. There is a PR on the attr_encrypted gem to fix this but the gem has not been updated in years and I doubt it will be now.GoRails published a tutorial on how to migrate your data from using attr_encrypted to using the rails 7 encryption. I did not want to pay for it so I checked out the git repo for the tutorial.
What they did is they decrypted the data themselves in a migration and updated the new encrypted fields manually.
Here is the link to their migration.
https://github.com/gorails-screencasts/migrate-attr_encrypted-to-rails-7-encryption/blob/master/db/migrate/20211005214633_migrate_encrypted_attributes.rb
a 新版本4.0.0 attr_encrypted 于2023年4月6日发布,并带有Rails 7支持。
A new version 4.0.0 of the gem
attr_encrypted
was released on April 6 2023 and it comes with Rails 7 support.基于先前的答案,两个方向都完全迁移:
Based on previous answer, a complete migration in both directions: