post.rb
@allowed_post_types = [
'type1',
'type2',
'type3',
'type4'
]
#validate post type
validates :post_type, :presence => true, :inclusion=> { :in => @allowed_post_types }, :if => :valid_post_type?
def valid_post_type?
self.post_type != 'type5'
end
validates :post_type
每当:post_type
不是type5时,我如何启用代码行?
尝试了上述方法,但似乎不起作用