Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6749699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:43:17+00:00 2026-05-26T12:43:17+00:00

(A) Like this: validates :network_id, :numericality => true validates :direct_url, :presence => true validates

  • 0

(A) Like this:

  validates :network_id,              :numericality => true

  validates :direct_url,              :presence => true

  validates :domain_name,             :presence => true

  validates :merchant_id,             :numericality => true

  validates :is_paid_merchant,        :presence => true

  validates :is_top_merchant,         :presence => true

  validates :last_months_revenue,     :presence => true,
                                      :numericality => true

  validates :name,                    :presence => true,
                                      :length => { :maximum => 50 }

  validates :primary_category_id,     :numericality => true

  validates :url,                     :presence => true

  validates :url_tag,                 :presence => true,
                                      :length => { :maximum => 45 }

-OR-

(B) like this:

  validates :network_id,
            :merchant_id,
            :last_months_revenue,
            :primary_category_id,      :numericality => true

  validates :direct_url,
            :domain_name,
            :is_paid_merchant,
            :is_top_merchant,
            :last_months_revenue,
            :name,
            :url,
            :url_tag,                 :presence => true

  validates :name,                    :length => { :maximum => 50 }

  validates :url_tag,                 :length => { :maximum => 45 }

In the first case each field has it’s own validates clause and in the second it’s based on what is being validated (fields that have multiple validations appear multiple times). The first case is also in alphabetical order so is a little more helpful to jump right to a specific field.

-OR-

(C) Am I just too anal retentive about how my code reads and looks?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:43:18+00:00Added an answer on May 26, 2026 at 12:43 pm

    I think the first style is better for the following reason:

    It’s most likely that you have a specific field name ‘in mind’ when working on a validation – or editing one – or adding a new validation for that field. So a system that lists each field and then all the validations for each one works well to read.

    The other style – group validations together tends to lead to seeing a field in one spot but then having to search and scroll around for other validations for that field – and there’s a good chance that you will not see or know about the other validations for that field which may be ‘off-screen’ and thus missed.

    This also may not be that big a deal when initially building the application (when the first style might actually seem easier) but going forward when you are adding or removing or changing fields and validations (i.e. ‘application building in the real world!’) it will be easier and less error-prone if all the validations for a given field are together.

    Another example of why B) is bad…
    Imagine this:

      validates :network_id,
                :merchant_id,
                :last_months_revenue,
                :primary_category_id,      :numericality => true
    
      validates :network_id,
                :direct_url,
                :domain_name,
                :merchant_id,
                :url,
                :url_tag,                 :presence => true
    
      validates :network_id              :uniqueness => true
    

    See how field are repeated all over the place?
    Now imagine removing network_id – yuch!
    Now imagine adding another _id field that needs numericality, uniqueness and presence – yuch!

    Another example – one might think (ok, I’ve done long ago), i’ll group all the ‘required’s together and then put a nice comment for them and then all the uniquesness of’s, with a comment header label for all of them, etc. So there is a ‘standard’ for developers to follow. The problem with an approach like this (apart from the previous comments) is that this is a ‘local’ standard that other programmers (both current and future) will need to understand and then… hopefully… follow. Much as I love them myself, personal standards like this often contribute to technical debt unless clearly thought out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I validate a surname field like this validates :surname, :presence => true, :length =>
I have a user model like this: class User < ActiveRecord::Base validates :password, :presence
How should I test a validation with a conditional like this: validates :age, :numericality
I want to do something like this: $('.dynamicHtmlForm').validate = function() { return true; }
I have a XML file that looks like this <Licence> <Name>Test company</Name> <Version>1.1.1.1</Version> <NumberOfServer>2</NumberOfServer>
I have a model that looks like this - class Car < ActiveRecord::Base validates
I got a javascript code like this to validate the file extension for my
What is the regular expression to validate a comma delimited list like this one:
I've got a model like this def upload_location(instance, filename): return 'validate/%s/builds/%s' % (get_current_user(), filename)
I'm using the jQuery validate plugin to validate a multi-step form like this one:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.