出于某种原因,我需要运行此验证
validates_presence_of :user_id
就在调用某个方法时
def publish # this method does not save nor update record
# so validations are not run
...
end
我已经这样解决了:
# model
validates_presence_of :user_id, if: :going_to_publish
attr_accessor :going_to_publish
# when calling publish
post.going_to_publish = true
post.publish
有没有办法删除那个标志变量?