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

  • SEARCH
  • Home
  • 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 6578489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:46:38+00:00 2026-05-25T15:46:38+00:00

In a plugin I am writing I am using alias to override one of

  • 0

In a plugin I am writing I am using alias to override one of the default Rails validators like so:

# Alias the original validator so it's still available under a different name
alias original_validates_uniqueness_of :validates_uniqueness_of unless method_defined?(:original_validates_uniqueness_of)
# Then alias the custom validator under the original name
alias validates_uniqueness_of :custom_validates_uniqueness_of

This all works pretty well. When “validates_uniqueness_of” is defined on an attribute in a AR model, it will use my “custom_validates_uniqueness_of” method instead. Validations are running as expected.

However, when I call:

SomeARclass.respond_to?(:validates_uniqueness_of)

..it will return false. This behavior will mess with several popular plugins.

My question:
Why is respond_to returning “false”? Is this behavior the result of alliasing? How can adjust my custom validator to make it return true?

Thank you for your help.
Erwin

  • 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-25T15:46:39+00:00Added an answer on May 25, 2026 at 3:46 pm

    Your sample, on the surface, looks like it should work. I expect you’ve found that, inside of the class body for class SomeARclass, you actually can call validates_uniqueness_of.

    class SomeARclass
      validates_uniqueness_of :first_field # works
    end
    

    However, I expect that scoped_validates_uniqueness_of is a private method. That’s why you have been unable to send that message to SomeARclass from outside of its class body.

    SomeARclass.validates_scoped_uniqueness_of :first_field # fails
    #=> NoMethodError: private method "validates_scoped_uniqueness_of" called
        for SomeARclass:Class
    

    When you alias a private method with a new name, such as aliasing the private method validates_scoped_uniqueness_of with the new name validates_uniqueness_of, then that new method is also private. I expect that’s what happened here.

    The documentation for #respond_to? reads:

    - (Boolean) respond_to?(symbol, include_private = false)

    Returns true if obj responds to the given method. Private methods are included in the search only if the optional second parameter evaluates to true.

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

Sidebar

Related Questions

I'm writing a plugin that needs some inflections of it's own. Using rails 2.3
I am writing one plugin using NPAPI. I was looking for simple example which
I'm writing a semi-generic form plugin using jQuery in order to speed up the
I'm writing a C++ plugin in Mac OS X using the Carbon framework (yeah,
I'm writing a plugin that's modifying an existing UI. One thing I want to
I am writing an installer using Wix 3 which installs a plugin to a
I am using Eclipse Helios with Android SDK plugin and writing for Android 2.2
Hey guys, I'm writing a Firefox plugin and using the following function: var obj
I've been using jQuery a long time and I've been writing a slideshow plugin
I am writing a plugin using the standard authoring pattern for jQuery, using methods

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.