我在一个Order表中有一个字段,它由其他值填充,按照下面的示例工作得很好:
company_name: A-Z Traders
company_tel: (111) 111 1111
MD5_hash_field: A-Z Traders|(011) 111 1111这是通过隐藏字段创建记录。
我需要的是MD5_hash_field在保存到数据库之前对MD5进行哈希处理。
尝试添加以下内容:
before_create :hash_field
def hash_field
self.md5_field = Digest::MD5.hexdigest(self.md5_field)
end但似乎什么也没做
编辑:
这在一定程度上是可行的。
<%= f.hidden_field :checksum, :value => '10011013800|Customer1|3299|ZAR|http://localhost|2012-01-30 18:30:00|secret' %>
Result should be: 31d1244f08a62f0551e9263c4835ba88
but getting : aae1ee590e4d4e08e7c0363cca90a22b已解决:
This Does Work! - Fellow Developers when working on multiple Applications make sure you are restarting the correct App. LOL发布于 2013-01-25 21:55:46
你不能把代码改成
def hash_field
p self.md5_field
self.md5_field = Digest::MD5.hexdigest(self.md5_field)
end看看它在日志里给了你什么?
https://stackoverflow.com/questions/14521511
复制相似问题