我的 Rails 应用程序正在获取两个模型的更改历史记录,使用如下所示的审计员 gem:
@audit = Audit.where( :auditable_id => current_user.posts,
:auditable_type => "Post") +
Audit.where( :auditable_id => @comments,
:auditable_type => "Comment")
这可行,但是我需要在进行@audit
更改时对整个变量进行排序。
我有两个问题要解决。
- 以下方法无效:
sort
,sort_by
,order
我需要弄清楚我需要按以下哪些字段进行排序:
=> Audit(id: integer, auditable_id: integer, auditable_type: string, owner_id: integer, owner_type: string, user_id: integer, user_type: string, action: string, audited_changes: text, version: integer, comment: text, **created_at**: datetime) 1.9.3-p194 :002 > Audit.last Audit Load (168.0ms) SELECT "audits".* FROM "audits" ORDER BY version DESC, created_at DESC LIMIT 1 => #<Audit id: 5, auditable_id: 58, auditable_type: "Post", owner_id: 58, owner_type: "Post", user_id: 1, user_type: "User", action: "update", audited_changes: {"status"=>["to approve", "to review"], " **updated_at** "=>[2012-08-24 15:29:26 UTC, 2012-08-24 19:29:52 UTC]}, version: 2, comment: "post modified by Bruno Amaral ", created_at : "2012-08-24 19:29:52">