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

JQuery Autocomplete without using label, value, id -

c++ - Accessing inactive union member and undefined behavior? -

JAVA - what is the difference between void and boolean methods? -