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 8325483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:27:08+00:00 2026-06-09T00:27:08+00:00

Summary : I’m trying to alter an attribute’s value within a custom ActiveModel::EachValidator validator.

  • 0

Summary: I’m trying to alter an attribute’s value within a custom ActiveModel::EachValidator validator. Given the following prototype:

def validate_each(record, attribute, value)

trying to set value = thing doesn’t appear to do anything — am I missing something? There should be a smart way to do this…

Detail: I accept a URL input as part of a site. I don’t want to just take the URL and directly validate that it returns a 200 OK message, because that would ignore entries that didn’t start with http, or left out the leading www, etc. I have some custom logic to deal with those errors and follow redirects. Thus, I’d like the validation to succeed if a user types in example.org/article rather than http://www.example.org/article. The logic works properly inside the validation, but the problem is that if somebody types in the former, the stored value in the database is in the “wrong” form rather than the nicely updated one. Can I change the entry during validation to a more canonical form?

  • 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-06-09T00:27:10+00:00Added an answer on June 9, 2026 at 12:27 am

    You should leave the validation to do just that: validate; it’s not the right place to manipulate your model’s attributes.

    See ActiveModel’s before_validation callback. This is a more appropriate place to be manipulating model attributes in preparation for validation.

    It looks like you have to tell your ActiveModel implementation about callbacks, at least according to this SO question.

    class YourModel
      extend ActiveModel::Callbacks
      include ActiveModel::Validations
      include ActiveModel::Validations::Callbacks
    
      before_validation :manipulate_attributes
    
      def manipulate_attributes
        # Your manipulation here.
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Summary: I want to display a value (in a text box) stored in another
Summary: I'm trying to write a text string to a column of type varchar(max)
Summary: I'm given a series of points in 3D space, and I want to
Summary : I have a table populated via the following: insert into the_table (...)
Summary Hi All, OK, further into my adventures with custom controls... In summary, here
Summary: How do I expand a property with value download\${bulidmode}\project\setup.msi to download\Debug\project\setup.msi if the
Summary: I'm trying to use stored Google accounts on an Android application to authenticate
Summary: I am trying to use asp.net membership, roles, and profiles, but am having
Summary: I want a horizontal row of ImageButtons to scale down evenly to fit
Summary For some reason, git commands don't work the same when I am logged

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.