开发者

#validate does not seem to work correctly with :on => :create/:update

Greetings,

I have a custom validation in my exemplary Movie model:

class Movie <开发者_开发百科 ActiveRecord::Base
  validate :it, :on => :create

  private

  def it
    self.errors.add 'foo', 'bar'
  end
end

This works on movie creation but also on updating an existing movie. :on => :update will also work for both. Might that be a bug or am I missing something?

Best regards

Tobias


i think you should use validate_on_create instead

like

validate_on_create :it


FYI, and only because I saw it in my server console:

DEPRECATION WARNING: validate_on_create is deprecated. Please use validate(args, :on => :create).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜