开发者

Rails - really_create_a_version in the model

I'm using the Rails 3 Vestal Versions 开发者_运维问答gem: https://github.com/lailsonbm/vestal_versions

I'd like to create some logic to determine if/when to create a new version on a model update. Per the specs, I did:

class Note < ActiveRecord::Base
    versioned :if => :really_create_a_version?

  def really_create_a_version
    Rails.logger.debug 'really_create_a_version really_create_a_version really_create_a_version really_create_a_version - START'
    record.inspect
    @note = Note.find(32)
    Rails.logger.debug 'really_create_a_version really_create_a_version really_create_a_version really_create_a_version - END'
  end

end

But that doesn't work, I get the following error:

NoMethodError (undefined method `really_create_a_version?' for #<Note:0x155c39a28>):
  app/controllers/notes_controller.rb:124:in `update'

Any suggestions or ideas? thxs

UPDATE

Conditional version creation. The versioned method now accepts :if and :unless options. Each expects a symbol representing an instance method or a proc that will be evaluated to determine whether or not to create a new version after an update. An array containing any combination of symbols and procs can also be given. class User < ActiveRecord::Base versioned :if => :really_create_a_version? end


Define your method like this

def really_create_a_version?

You are missing the trailing ?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜