いつも通り以下の様なvalidatesをモデルに書いていたとする

app/models/user.rb
  validates :name, presence: true
  validates :email, presence: true
  validates :password, presence: true

1.validate用ファイルを作りvalidatesを移動する

app/models/validatos/user.rb
+ {  module Validators::User
+    def self.included(klass)
+      klass.validates :name, presence: true
+      klass.validates :email, presence: true
+      klass.validates :password, presence: true
+    end
+  end
app/models/user.rb
-  validates :name, presence: true
-  validates :email, presence: true
-  validates :password, presence: true

2.1で作ったファイルをincludeする

:app/models/user.rb
+  include Validators::User
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.