开发者

act_as_revisable returns ObjectRevision instead of just Revision

开发者 https://www.devze.com 2022-12-08 07:57 出处:网络
I have a model Item: class Item < ActiveRecord::Base acts_as_revisable end When I try to use Item.find(2, :with_revisions) it comes back as an ItemRevision class instead of an Item class and I c

I have a model Item:

class Item < ActiveRecord::Base
  acts_as_revisable
end

When I try to use Item.find(2, :with_revisions) it comes back as an ItemRevision class instead of an Item class and I can'开发者_开发百科t do things like assigning from another model (i.e. ItemList.items << item).

Is there a way to make it return Item or a way to make it into an Item?


When you have a revision object you can call a method on it to get what it's a revision for:

@page.revisions.first.page

In this example I have the Page model which has versions for its records, and on every version there is a page method to get the object to which that version references.

0

精彩评论

暂无评论...
验证码 换一张
取 消