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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:45:33+00:00 2026-05-27T14:45:33+00:00

Is there a way to enforce that a controller inherits from another one in

  • 0

Is there a way to enforce that a controller inherits from another one in the route declaration? For example, if class B was a subclass of class A, allow it to use the route. Something like this?

match '/login/:controller', :constraint => { :inherits => A }

Update

As a more concrete example, I have an OAuthController that accepts logins from several sources. Let’s say Google, Facebook, and Twitter. I have a GoogleController, FacebookController, and TwitterController that are all subclasses of OAuthController. So right now I accept the following routes:

/login/google
/login/facebook
/login/twitter

I might add or remove others at any time but I don’t want to change my route. I also only want the :controller to be a subclass of :OAuthController. Is there a way to enforce that?

  • 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-27T14:45:34+00:00Added an answer on May 27, 2026 at 2:45 pm

    I don’t think that there is support out of the box for what you want to reach. However, there may be a way to go for. Have a look at “Rails Guides to Routing, Advanced Constraints”. It uses a request object which is not exactly what you want to have, but may be sufficient.

    The idea goes like that:

    • Implement a constraint with the necessary methods.
    • In the method matches?(request), do what you want to prove.
    • Integrate it by adding the route constraint:

      match "*path" => "login/:action",
        :constraints => LoginConstraint.new
      

    This is the code for the implementation:

    class BlacklistConstraint
      def initialize
        ... # necessary initialization here
      end
    
      def matches?(request)
        ... # Here is your check that returns true or false
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In SQL, is there a way to enforce that only one column out of
Is there a way to enforce/limit the types that are passed to primitives? (bool,
Is there a way to enforce that a type parameter passed to an attribute
Is there any way to enforce that a method call in soap based wcf
Quick one: Is there any way to enforce types for variadic functions in PHP?
Is there a way to enforce constraint checking in MSSQL only when inserting new
Is there any way to enforce a template in Bugzilla to guide users fill
Is there any way in Java to enforce a minimum window size? The last
is there way how to get name ov event from Lambda expression like with
Is there a product/project that would allow you to define conventions for say an

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.