<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>mofmof-inc</author_name>
  <author_url>https://blog.hatena.ne.jp/mofmof-inc/</author_url>
  <blog_title>もふもふ技術部</blog_title>
  <blog_url>https://www.mof-mof.co.jp/tech-blog/</blog_url>
  <categories>
    <anon>共通バリデーション</anon>
    <anon>ActiveModel::EachValidator</anon>
    <anon>Rails</anon>
  </categories>
  <description>アプリケーションを開発していると、電話番号やURL、カナなど複数のモデルで同じバリデーションを定義していることがある。 上記の例くらいなら、同じバリデーションルールを複数箇所で書いても良さそうだが、変更が生じた時やもう少し複雑なバリデーションを記述する場合、面倒なことになる。 そこで今回は、Railsではどうやってバリデーションルールを共通化させるかについて解説する。 まず、Railsではこのようなルールを定義して利用するための基底クラスとして、ActiveModel::EachValidatorとActiveModel::Validatorが用意されている。 本記事ではまずActiveMod…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fwww.mof-mof.co.jp%2Ftech-blog%2Frails-each-validator&quot; title=&quot;Railsでモデル層からバリデーションを切り出して共通のバリデーションルールを定義する ActiveModel::EachValidator編 - もふもふ技術部&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2021-01-15 00:00:00</published>
  <title>Railsでモデル層からバリデーションを切り出して共通のバリデーションルールを定義する ActiveModel::EachValidator編</title>
  <type>rich</type>
  <url>https://www.mof-mof.co.jp/tech-blog/rails-each-validator</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
