保存前的MD5哈希值

时间:2013-01-25 12:07:19

标签: ruby-on-rails ruby-on-rails-3 md5

我在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

1 个答案:

答案 0 :(得分:0)

无法将代码更改为

def hash_field
  p self.md5_field
  self.md5_field = Digest::MD5.hexdigest(self.md5_field)
end

看看它在日志中提供了什么?

相关问题