我需要比较两个活动的记录,并获得已更改列比较两个记录,并获得已更改列的名称在轨活动记录
#<Evaluation id: 1, name: "Foo", status: "yes", comments: "can be better", created_at: "2017-05-09 12:00:00", updated_at: "2017-05-09 12:00:00">
#<Evaluation id: 2, name: "Foo", status: "yes", comments: "keep up the good work", created_at: "2017-05-09 12:05:00", updated_at: "2017-05-09 12:05:00">
我需要比较这两个记录,并得到的名称更改的列的名称。在这种情况下:comments, :created_at, :updated_at
我一直在使用的方法,如eql?
,record1.attributes.except('id') == record2.attributes.except('id')
这些只返回true或false我需要得到的列名,以及尝试。 这可以通过比较每列来完成,但我正在寻找任何其他选项。
看起来像它的缺失为Rails'4.2','5.0'一个Gemfile中和'5.1' - 那里有大约3年没有任何承诺。 (虽然它应该很容易更新!) –
通过命令将对象更改为散列:obj.attributes然后安装gem hashdiff(https://github.com/liufengyun/hashdiff)并将其比较 – puneet18
我可以确认activerecord-diff作品很棒的Rails 5.0.1和红宝石2.3.1。只需在你的application.rb文件中使用require'active_record/diff' – Augusto