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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:56:07+00:00 2026-05-26T21:56:07+00:00

I’m trying to get will_paginate working with Sinatra and I have a stange problem

  • 0

I’m trying to get will_paginate working with Sinatra and I have a stange problem with will_paginate and DataMapper. So I have a code:

require 'data_mapper'
require 'will_paginate'
require 'will_paginate/data_mapper'
class User
  include DataMapper::Resource

  property :id,   Serial    # primary serial key
  property :username, String, length: 5..15, unique: true
  property :fullname, String, length: 5..25
  property :email, String, required: true, unique: true, format: :email_address
  property :hashed_password, String
  property :created_at, Time, required: true
  property :auth_token, String
  property :locale, String

  has n, :items
end

class Item
  include DataMapper::Resource
  property :id, Serial
  property :question, String, required: true
  property :answer, String, required: true
  property :ef, Float
  property :interval, Float
  property :created_at, Time
  property :updated_at, Time
  property :reviev_at, Time

  belongs_to :user
end

DataMapper::setup(:default, "sqlite3://#{File.expand_path(File.dirname(__FILE__))}/database2.db")
DataMapper.finalize
DataMapper.auto_upgrade!

u = User.first
p = u.items.paginate(page: 1)
puts p.total_entries

And running it causes a problem:

/home/changs/src/PwS/vendor/bundle/ruby/1.9.1/gems/dm-core-1.1.0/lib/dm-core/query.rb:942:in `assert_valid_order': +options[:order]+ should not be empty if +options[:fields] contains a non-operator (ArgumentError)
    from /home/changs/src/PwS/vendor/bundle/ruby/1.9.1/gems/dm-core-1.1.0/lib/dm-core/query.rb:773:in `block in assert_valid_options'
    from /home/changs/src/PwS/vendor/bundle/ruby/1.9.1/gems/dm-core-1.1.0/lib/dm-core/query.rb:766:in `each'
    from /home/changs/src/PwS/vendor/bundle/ruby/1.9.1/gems/dm-core-1.1.0/lib/dm-core/query.rb:766:in `assert_valid_options'
    from /home/changs/src/PwS/vendor/bundle/ruby/1.9.1/gems/dm-core-1.1.0/lib/dm-core/query.rb:363:in `update'
    from /home/changs/src/PwS/vendor/bundle/ruby/1.9.1/gems/dm-core-1.1.0/lib/dm-core/query.rb:386:in `merge'
    from /home/changs/src/PwS/vendor/bundle/ruby/1.9.1/gems/will_paginate-3.0.2/lib/will_paginate/data_mapper.rb:54:in `total_entries'
    from test.rb:39:in `<main>'

But if I comment out last three lines it works in irb as fallow:

ruby-1.9.2-p290 :001 > require './test' # file with deleted last 3 lines
 => true 
ruby-1.9.2-p290 :002 > u = User.first
 => #<User @id=1 @username="Testt" @fullname="tetestse" @email="test@wp.pl" @hashed_password=nil @created_at=2011-11-14 00:00:00 +0100 @auth_token=nil @locale=nil> 
ruby-1.9.2-p290 :003 > p = u.items.paginate(page: 1)
 => [#<Item @id=1 @question="A" @answer="B" @ef=nil @interval=nil @created_at=2011-11-14 00:00:00 +0100 @updated_at=2011-11-14 00:00:00 +0100 @reviev_at=nil @user_id=1>, #<Item @id=2 @question="C" @answer="D" @ef=nil @interval=nil @created_at=2011-11-14 00:00:00 +0100 @updated_at=2011-11-14 00:00:00 +0100 @reviev_at=nil @user_id=1>] 
ruby-1.9.2-p290 :004 > puts p.total_entries 
2
 => nil 
  • 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-26T21:56:08+00:00Added an answer on May 26, 2026 at 9:56 pm

    This happens because p isn’t loaded when p.total_entries is called from the script. In irb printing the value after setting p causes it to be loaded. You can work around it by reloading before calling total_entries, like this:

    u = User.first
    p = u.items.paginate(page: 1)
    p.reload
    puts p.total_entries
    

    To me this seems like a bug in will_paginate that should be reported.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have been unable to fix a problem with Java Unicode and encoding. The
I am trying to loop through a bunch of documents I have to put
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

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.