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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:05:04+00:00 2026-05-16T07:05:04+00:00

I have a method that does a paginated find call like.. 1 coll =

  • 0

I have a method that does a paginated find call like..

1

coll = paginate(:all, lambda {{:conditions => ['status = ? AND expires < ?', 'a', DateTime.now]}}, :select => Constants::POST_FIELDS,
                   :order => 'posts.ratings DESC', :include => [{:poster => :poster_friends}, :category], :per_page => Constants::LISTINGS_PER_PAGE,
                   :page => page)

When this call runs it simply ignores the conditions in the generated query.

2

If I try it in a named_scope I get an error like..

named_scope :featured_all, lambda {{:conditions => ['status = ? AND expires < ?', 'a', DateTime.now], order => 'posts.ratings DESC', :include => [{:poster => :poster_friends},  :category],
            :select => Constants::POST_FIELDS}}

The named-scope error :

/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/keys.rb:47:in `assert_valid_keys'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2101:in `with_scope'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:113:in `__send__'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:113:in `with_scope'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:174:in `method_missing'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:188:in `load_found'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:166:in `proxy_found'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:109:in `is_a?'
    /usr/lib/ruby/gems/1.8/gems/hirb-0.3.1/lib/hirb/formatter.rb:78:in `determine_output_class'
    /usr/lib/ruby/gems/1.8/gems/hirb-0.3.1/lib/hirb/formatter.rb:48:in `format_output'
    /usr/lib/ruby/gems/1.8/gems/hirb-0.3.1/lib/hirb/view.rb:213:in `render_output'
    /usr/lib/ruby/gems/1.8/gems/hirb-0.3.1/lib/hirb/view.rb:126:in `view_output'

For #1. What am I doing wrong, why is it ignoring the conditions?

For #2 Why this error? And also, how can I pass the :page and per_page parameter to limit the query in the named_scope.

Thanks

  • 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-16T07:05:05+00:00Added an answer on May 16, 2026 at 7:05 am

    Your use case does not warrant a named_scope. You can write a regular finder as follows:

    coll = paginate(:select     => Constants::POST_FIELDS,
                    :conditions => ['status = ? AND expires < ?', 'a', DateTime.now],
                    :include    => [{:poster => :poster_friends}, :category],
                    :order      => 'posts.ratings DESC',  
                    :per_page   => Constants::LISTINGS_PER_PAGE,
                    :page => page)
    

    The paginate method is equivalent to all, so you don’t have to supply the :all result-set scope qualifier to the paginate method.

    The time value is calculated upon the execution of the query. This is unlike a named_scope, where you have to use a lambda for the same effect.

    If you need to use the named_scope then do the following:

    named_scope :featured_all, lambda {{
                    :select     => Constants::POST_FIELDS,
                    :conditions => ['status = ? AND expires < ?', 'a', DateTime.now],
                    :include    => [{:poster => :poster_friends}, :category],
                    :order      => 'posts.ratings DESC'
                   }}
    

    Now you can use the named_scope as follows

    Post.feature_all.paginate(:per_page => Constants::LISTINGS_PER_PAGE, 
                              :page => page)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have method that does asynchronous call to web service. Something like that: public
I have a method that does a time consuming operation, say something like ten
I have a method that does some IO, and I'd like to limit the
I have extension method that does something like this public static void DoStuff(this ObjectContext
I'm trying to not repeat code, so I have a method that does a
I know that an interface does not have a body, just a method definition.
If I have a method that does not specify its Accessibility Level will it
If I have a method that does multiple, related things, is it good practice
I have a method that does something, and it puts a javascript method into
I have a method that does temperature conversions. The method is intended to raise

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.