{"id":476,"date":"2008-04-24T03:26:06","date_gmt":"2008-04-23T18:26:06","guid":{"rendered":"http:\/\/ecpplus.net\/weblog\/?p=476"},"modified":"2020-06-15T22:18:49","modified_gmt":"2020-06-15T13:18:49","slug":"skip_validation_on_active_record","status":"publish","type":"post","link":"https:\/\/ecpplus.net\/weblog\/skip_validation_on_active_record\/","title":{"rendered":"AR\u3067Validation\u3092Skip\u3057\u3066\u4fdd\u5b58\u3059\u308b"},"content":{"rendered":"<p>\u3000AJAX\u3067\u51e6\u7406\u66f8\u304f\u3068\u3001\u3069\u3046\u3057\u3066\u3082Create\u306e\u6642\u306f\u30c7\u30fc\u30bf\u304c\u4e0d\u5b8c\u5168\u3067\u3082\u3068\u308a\u3042\u3048\u305a\u4f5c\u308a\u305f\u3044\u3002\u307f\u305f\u3044\u306a\u3053\u3068\u304c\u3042\u3063\u3066\u3001\u305d\u308c\u306f <code>validate_on_create, validate_on_update<\/code> \u3067\u5206\u3051\u305f\u308a\u3001\u5404 <code>validates_on_** :on =&gt; :update<\/code> \u307f\u305f\u3044\u306a\u611f\u3058\u306b\u304b\u3051\u3070\u3044\u3044\u3093\u3060\u3051\u3069\u3001<code>sortable_list<\/code> \u3068\u304b\u3067\u5358\u4e00\u30d5\u30a3\u30fc\u30eb\u30c9\u3060\u3051\u3054\u306b\u3087\u3054\u306b\u3087\u3084\u308a\u305f\u3044\u3068\u304d\u306f\u7d50\u69cb\u56f0\u308b\u3002<\/p>\n<p>\u3000\u305d\u3093\u306a\u3068\u304d\u306b\u4f7f\u3048\u305d\u3046\u306a\u30e1\u30bd\u30c3\u30c9\u3002\u304c\u3042\u3063\u305f\u3093\u3060\u3051\u3069\u3001\u7279\u306b\u5fc5\u8981\u304c\u306a\u304b\u3063\u305f\u3053\u3068\u304c\u308f\u304b\u3063\u305f\u3068\u3044\u3046\u8a71\u3002<\/p>\n<h3>activerecord-2.0.2\/lib\/active_record\/validations.rb : line 932<\/h3>\n<p>\u5f15\u6570\u306bfalse\u6e21\u305b\u3070\u3001Validation\u3092\u30b9\u30ad\u30c3\u30d7\u3057\u3066save\u51fa\u6765\u308b\u3002<\/p>\n<pre><code class=\"language-ruby line-numbers\">    # The validation process on save can be skipped by passing false. The regular Base#save method is\n    # replaced with this when the validations module is mixed in, which it is by default.\n    def save_with_validation(perform_validation = true)\n      if perform_validation &amp;&amp; valid? || !perform_validation\n        save_without_validation\n      else\n        false\n      end\n    end\n<\/code><\/pre>\n<h3>activerecord-2.0.2\/lib\/active_record\/validations.rb : line 953<\/h3>\n<p>\u3000\u3053\u3063\u3061\u306f\u3001update_attribute \u306eValidation\u7121\u3057\u7248\u3002<\/p>\n<pre><code class=\"language-ruby line-numbers\">    # Updates a single attribute and saves the record without going through the normal validation procedure.\n    # This is especially useful for boolean flags on existing records. The regular +update_attribute+ method\n    # in Base is replaced with this when the validations module is mixed in, which it is by default.\n    def update_attribute_with_validation_skipping(name, value)\n      send(name.to_s + '=', value)\n      save(false)\n    end\n<\/code><\/pre>\n<p>\u3068\u601d\u3063\u3066\u30bd\u30fc\u30b9\u3092\u898b\u3066\u307f\u305f\u3093\u3060\u3051\u3069\u3001save(false) \u3063\u3066\u66f8\u3044\u3066\u3042\u3063\u3066\u3001\u3069\u3046\u307f\u3066\u3082 Validation\u3092Skip\u3059\u308b\u65b9\u6cd5\u3067\u3057\u305f\u3002<\/p>\n<p><strong>validation \u3092 skip \u3057\u3066 save \u3059\u308b\u3068\u304d\u306f \u5f15\u6570\u306b false \u3092\u6e21\u3059 save(false) \u3068\u3044\u3046\u3053\u3068\u3089\u3057\u3044\u3002<\/strong><\/p>\n<p><code>update_attribute_with_validation_skipping(name, value)<\/code> \u3068\u304b\u306f\u3001\u3071\u3063\u3068\u307f\u3066\u4f55\u3084\u3063\u3066\u308b\u304b\u308f\u304b\u308b\u3093\u3060\u3051\u3069\u3001 <code>save_with_validation(false)<\/code> \u306f\u4e00\u898b\u3057\u3066\u4f55\u3057\u3066\u308b\u304b\u5206\u304b\u308a\u306b\u304f\u3044\u3051\u3069\u3001 <code>save(false)<\/code> \u3092\u77e5\u3089\u306a\u3044\u306a\u3089\u3069\u3063\u3061\u898b\u3066\u3082\u5206\u304b\u3089\u306a\u3044\u304b\u3089\u304b\u308f\u3089\u3093\u306d\u30fc\u3002\u3068\u601d\u3063\u305f\u3088\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000AJAX\u3067\u51e6\u7406\u66f8\u304f\u3068\u3001\u3069\u3046\u3057\u3066\u3082Create\u306e\u6642\u306f\u30c7\u30fc\u30bf\u304c\u4e0d\u5b8c\u5168\u3067\u3082\u3068\u308a\u3042\u3048\u305a\u4f5c\u308a\u305f\u3044\u3002\u307f\u305f\u3044\u306a\u3053\u3068\u304c\u3042\u3063\u3066\u3001\u305d\u308c\u306f validate_on_create, validate_on_update \u3067\u5206\u3051\u305f\u308a\u3001\u5404 val [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2521,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[10],"class_list":["post-476","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-rails"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"AJAX\u3067\u51e6\u7406\u66f8\u304f\u3068\u3001\u3069\u3046\u3057\u3066\u3082Create\u306e\u6642\u306f\u30c7\u30fc\u30bf\u304c\u4e0d\u5b8c\u5168\u3067\u3082\u3068\u308a\u3042\u3048\u305a\u4f5c\u308a\u305f\u3044\u3002\u307f\u305f\u3044\u306a\u3053\u3068\u304c\u3042\u3063\u3066\" \/>\n\t<meta name=\"robots\" content=\"max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n\t<meta name=\"author\" content=\"\u3061\u3085\u3046\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/ecpplus.net\/weblog\/skip_validation_on_active_record\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"ja_JP\" \/>\n\t\t<meta property=\"og:site_name\" content=\"\u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"AR\u3067Validation\u3092Skip\u3057\u3066\u4fdd\u5b58\u3059\u308b | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0\" \/>\n\t\t<meta property=\"og:description\" content=\"AJAX\u3067\u51e6\u7406\u66f8\u304f\u3068\u3001\u3069\u3046\u3057\u3066\u3082Create\u306e\u6642\u306f\u30c7\u30fc\u30bf\u304c\u4e0d\u5b8c\u5168\u3067\u3082\u3068\u308a\u3042\u3048\u305a\u4f5c\u308a\u305f\u3044\u3002\u307f\u305f\u3044\u306a\u3053\u3068\u304c\u3042\u3063\u3066\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/ecpplus.net\/weblog\/skip_validation_on_active_record\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png\" \/>\n\t\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t\t<meta property=\"article:tag\" content=\"development\" \/>\n\t\t<meta property=\"article:tag\" content=\"rails\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2008-04-23T18:26:06+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2020-06-15T13:18:49+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@ecpplus\" \/>\n\t\t<meta name=\"twitter:title\" content=\"AR\u3067Validation\u3092Skip\u3057\u3066\u4fdd\u5b58\u3059\u308b | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0\" \/>\n\t\t<meta name=\"twitter:description\" content=\"AJAX\u3067\u51e6\u7406\u66f8\u304f\u3068\u3001\u3069\u3046\u3057\u3066\u3082Create\u306e\u6642\u306f\u30c7\u30fc\u30bf\u304c\u4e0d\u5b8c\u5168\u3067\u3082\u3068\u308a\u3042\u3048\u305a\u4f5c\u308a\u305f\u3044\u3002\u307f\u305f\u3044\u306a\u3053\u3068\u304c\u3042\u3063\u3066\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@ecpplus\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"AR\u3067Validation\u3092Skip\u3057\u3066\u4fdd\u5b58\u3059\u308b | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","description":"AJAX\u3067\u51e6\u7406\u66f8\u304f\u3068\u3001\u3069\u3046\u3057\u3066\u3082Create\u306e\u6642\u306f\u30c7\u30fc\u30bf\u304c\u4e0d\u5b8c\u5168\u3067\u3082\u3068\u308a\u3042\u3048\u305a\u4f5c\u308a\u305f\u3044\u3002\u307f\u305f\u3044\u306a\u3053\u3068\u304c\u3042\u3063\u3066","canonical_url":"https:\/\/ecpplus.net\/weblog\/skip_validation_on_active_record\/","robots":"max-snippet:-1, max-image-preview:large, max-video-preview:-1","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"ja_JP","og:site_name":"\u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","og:type":"article","og:title":"AR\u3067Validation\u3092Skip\u3057\u3066\u4fdd\u5b58\u3059\u308b | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","og:description":"AJAX\u3067\u51e6\u7406\u66f8\u304f\u3068\u3001\u3069\u3046\u3057\u3066\u3082Create\u306e\u6642\u306f\u30c7\u30fc\u30bf\u304c\u4e0d\u5b8c\u5168\u3067\u3082\u3068\u308a\u3042\u3048\u305a\u4f5c\u308a\u305f\u3044\u3002\u307f\u305f\u3044\u306a\u3053\u3068\u304c\u3042\u3063\u3066","og:url":"https:\/\/ecpplus.net\/weblog\/skip_validation_on_active_record\/","og:image":"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png","og:image:secure_url":"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png","og:image:width":1920,"og:image:height":768,"article:tag":["development","rails"],"article:published_time":"2008-04-23T18:26:06+00:00","article:modified_time":"2020-06-15T13:18:49+00:00","twitter:card":"summary_large_image","twitter:site":"@ecpplus","twitter:title":"AR\u3067Validation\u3092Skip\u3057\u3066\u4fdd\u5b58\u3059\u308b | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","twitter:description":"AJAX\u3067\u51e6\u7406\u66f8\u304f\u3068\u3001\u3069\u3046\u3057\u3066\u3082Create\u306e\u6642\u306f\u30c7\u30fc\u30bf\u304c\u4e0d\u5b8c\u5168\u3067\u3082\u3068\u308a\u3042\u3048\u305a\u4f5c\u308a\u305f\u3044\u3002\u307f\u305f\u3044\u306a\u3053\u3068\u304c\u3042\u3063\u3066","twitter:creator":"@ecpplus","twitter:image":"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png"},"aioseo_meta_data":{"post_id":"476","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":"","og_description":"","og_object_type":"article","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":"","og_article_tags":"","twitter_use_og":false,"twitter_card":"summary_large_image","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-01-02 15:53:46","updated":"2022-09-29 10:07:09","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/ecpplus.net\/weblog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/ecpplus.net\/weblog\/category\/development\/\" title=\"Development\">Development<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tAR\u3067Validation\u3092Skip\u3057\u3066\u4fdd\u5b58\u3059\u308b\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/ecpplus.net\/weblog"},{"label":"Development","link":"https:\/\/ecpplus.net\/weblog\/category\/development\/"},{"label":"AR\u3067Validation\u3092Skip\u3057\u3066\u4fdd\u5b58\u3059\u308b","link":"https:\/\/ecpplus.net\/weblog\/skip_validation_on_active_record\/"}],"_links":{"self":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/comments?post=476"}],"version-history":[{"count":3,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/476\/revisions"}],"predecessor-version":[{"id":2560,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/476\/revisions\/2560"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media\/2521"}],"wp:attachment":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media?parent=476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/categories?post=476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/tags?post=476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}