ruby - Rails put validation in a module mixin? -


some validations repetitive in models:

validates :name, :length => { :minimum => 2 }, :presence => true, :uniqueness => true validates :name_seo, :length => { :minimum => 2 }, :presence => true, :uniqueness => true 

how put in mixin? error if put 'em in mixin

app/models/validations.rb:5: undefined method `validates' validations:module (nomethoderror) 

module validations extend activesupport::concern included validates :name, :length => { :minimum => 2 }, :presence => true, :uniqueness => true validates :name_seo, :length => { :minimum => 2 }, :presence => true, :uniqueness => true end end 

the validates macro must evaluated in context of includer, not of module (like doing).


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -