Rails - 模型中的 real_create_a_version
我正在使用 Rails 3 Vestal Versions gem: https://github.com/lailsonbm/vestal_versions
我想要创建一些逻辑来确定是否/何时在模型更新时创建新版本。根据规格,我做了:
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
但这不起作用,我收到以下错误:
NoMethodError (undefined method `really_create_a_version?' for #<Note:0x155c39a28>):
app/controllers/notes_controller.rb:124:in `update'
有什么建议或想法吗? thxs
更新
有条件的版本创建。版本化方法现在接受 :if 和 :unless 选项。每个都需要一个代表实例方法或过程的符号,将对其进行评估以确定是否在更新后创建新版本。还可以给出包含符号和过程的任意组合的数组。 用户类< ActiveRecord::基础 版本控制:if => :真的创建版本吗? 结尾
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样定义你的方法
你缺少尾随的
?
Define your method like this
You are missing the trailing
?