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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:18:26+00:00 2026-05-19T00:18:26+00:00

Rails has these lovely chainable methods. How do I add my own? I thought

  • 0

Rails has these lovely chainable methods. How do I add my own? I thought of defining a class method in the model from which I want to invoke my custom method, but this would only work at the beginning of a “chain”:

class << self
  def order_by_specialness
    order(:specialness)
  end
end

I suspect I would need to extend ActiveRecord::Relation somehow, as this is what’s returned by the each of the chainable query methods. But from there, I’m at a loss.

  • 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-19T00:18:26+00:00Added an answer on May 19, 2026 at 12:18 am

    You want to use scope:

    scope :order_by_specialness, order(:specialness)
    

    Call with:

    User.order_by_specialness.first
    

    Although using order_by_specialness doesn’t really save you any time. You should use something just like special:

    User.special.first
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Rails has these cool properties that seem to be actually methods. For example: class
In Ruby on Rails, each model entity has a validate_on_ something hook method, that
Rails has the rest autho plugin which works well but is there a solution
I am working on a Rails application that has user authentication which provides an
We're hosting our Ruby on Rails application with the EngineYard App Cloud, which has
I have a rails time-based query which has some odd timezone sensitive behaviour, even
I have a rails model class class Model < ActiveRecord::Base has_many :object_collection def add_object(object)
I have a database labor which contains the tables that the rails application has
I am coming from a Spring/hibernate background. I have noticed that Rails has no
I have a Rails 3 app where each customer has his own subdomain. I

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.