我得到了日期时间字段order_confirmed_at和completion_confirmed_at
class CoolModel < ActiveRecord::Base
attr_accessible :order_confirmed, completion_confirmed
def order_confirmed
order_confirmed_at.present?
end
def order_confirmed=(state)
if state and order_confirmed_at.blank?
self.order_confirmed_at = Time.now
end
order_confirmed_at.present?
end
def completion_confirmed
completion_confirmed_at.present?
end
def completion_confirmed=(state)
if state and completion_confirmed_at.blank?
self.completion_confirmed_at = Time.now
end
completion_confirmed_at.present?
end
end
...所以在我看来,我可以检查订单已确认并完成的复选框
事情是:这不仅是重复,而且这些东西显然看起来很标准。因此,为了节省我编写 gem 的时间:是否有 rails gem/engine 这样做(或者可能是我不知道的 Rails 的一部分)?
class CoolModel < ActiveRecord::Base
#something like this
acts_even_coller_on :order_confirmed_at, :completion_confirmed_at
end