Closed noctivityinc closed 14 years ago
I haven't seen this error in practice or tests.
So I need some more info: How many fields/columns are you trying to display? What does Hirb::View.width give you after getting this error?
Looks like 24 columns in one case and width of 179.
Take a look at this: http://pastie.org/private/wmlut3wnkezcyzjdana4w
You can see the same command (Factory(:site)) issued with Hirb enabled and disabled. When disabled, no error.
Thanks!
Looks pretty bad but I can't reproduce.
Could you dump the attributes of the ActiveRecord object that's causing this into a pastie i.e.
Factory(:site).attributes?
What ruby version are you running? Maybe you're affected by this http://redmine.ruby-lang.org/issues/show/1397
I believe this is what you are looking for:
Site(id: integer, name: string, active: boolean, subdomain: string, styles: text, logo_file_name: string, logo_content_type: string, logo_file_size: integer, description: text, url: string, redirect_url: string, created_at: datetime, updated_at: datetime, creator_id: integer, updater_id: integer, is_default: boolean, order_complete_email_id: integer, support_url: string, support_contact: string, support_email: string, guarantee: text, general_contact_email: string, general_contact_name: string, order_contact_email: string, order_contact_name: string)
As for ruby,
09:41 AM ~/projects/master_the_test => ruby -v ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]
I dont think this is the referenced bug as it's only happening with Hirb enabled. Plus there are no floats in the above model :)
By attributes I mean both the names and values. It's the values which usually lead to edge cases. Calling #attributes on a AR object should do the trick.
As for the bug, it refers to a bug with to_f which there are plenty of calls to in Hirb when calculating the optimal table width. If your ruby version is running into a ruby bug there's not much I can do about it.
Here you go
=> #<Site id: 242, name: "t2rYt76Jr7XYtGUE", active: nil, subdomain: "LYKxUdlzdUgy8j7v", styles: nil, logo_file_name: nil, logo_content_type: nil, logo_file_size: nil, description: nil, url: "http://www.qkmnXYAZ6MTroRGQ.com", redirect_url: "http://www.1dXJuTn6ZOIoDRK1.com", created_at: "2010-01-28 15:57:53", updated_at: "2010-01-28 15:57:53", creator_id: nil, updater_id: nil, is_default: false, order_complete_email_id: 246, support_url: "http://www.BVsanZiwDiE9R4wH.com", support_contact: "GGEtNVhVBFb8UrFn", support_email: "U8ssn4TuvzEhWzc8", guarantee: nil, general_contact_email: "yhall@privacy.net", general_contact_name: "PHjHW9vCHOGzJZBP", order_contact_email: "qtaylor@privacy.net", order_contact_name: "WdYhxyAQ8XTRV3xt">
I'm not seeing the warnings on 1.8.6 or 1.9.1. Seeing that your ruby version is the same version (down to the patchlevel) as the above bug report, I'm assuming you're running into buggy 1.8.7.
Proposed solutions:
To get Hirb working in some way, you can switch to vertical mode:
Hirb.enable :output=>{"Site"=>{:options=>{:vertical=>true}}}
Or you can turn of the auto-resizing of width that probably involves calling Rational#to_f
Hirb.enable :output=>{"Site"=>{:options=>{:field_lengths=>{} }}}
The latest hirb release may fix this issue. If it doesn't, I'll need a test case that confirms the bug exists for both of us. Until then I'll assume it's related to the above 1.8.7 bug. Feel free to reopen. Note: Proposal #4 has changed to:
Hirb.enable :output=>{"Site"=>{:options=>{:resize=>false} } }
Actually I rvmed 1.9.1 with Hirb and with Hirb enabled on large tables, IRB CRASHED. No output at all, just hung
Actually this is more interesting now with the latest release:
ree-1.8.7-2010.01 > Site.first
=> #<Site id: 1, name: "TheDMVTest.com", active: true, subdomain: "tdt", styles: "@import blueprint/colors.sass\n\n!base_font_size = 13...", logo_file_name: nil, logo_content_type: nil, logo_file_size: nil, description: nil, url: "http://www.thedmvtest.com", redirect_url: "http://www.thedmvtest.com", created_at: "2010-02-16 16:18:21", updated_at: "2010-02-16 16:18:21", creator_id: nil, updater_id: nil, is_default: true, support_url: "http://www.thedmvtest.com/support", support_contact: "Josh", support_email: "support@thedmvtest.com", guarantee: "<b>This is the guarantee</b>It's very good for stuf...", general_contact_email: "study@thedmvtest.com", general_contact_name: "Josh", order_contact_email: "orders@thedmvtest.com", order_contact_name: "Josh">
ree-1.8.7-2010.01 > Hirb.enable
=> true
ree-1.8.7-2010.01 > Site.first
/Users/jlippiner/.rvm/rubies/ree-1.8.7-2010.01/lib/ruby/1.8/rational.rb:390: warning: Bignum out of Float range
/Users/jlippiner/.rvm/rubies/ree-1.8.7-2010.01/lib/ruby/1.8/rational.rb:390: warning: Bignum out of Float range
/Users/jlippiner/.rvm/rubies/ree-1.8.7-2010.01/lib/ruby/1.8/rational.rb:390: warning: Bignum out of Float range
Hirb Error: comparison of Rational with Float failed
/Users/jlippiner/.rvm/gems/ree-1.8.7-2010.01%tdt/gems/hirb-0.2.10/lib/hirb/helpers/table/resizer.rb:30:in `>'
/Users/jlippiner/.rvm/gems/ree-1.8.7-2010.01%tdt/gems/hirb-0.2.10/lib/hirb/helpers/table/resizer.rb:30:in `adjust_long_fields'
/Users/jlippiner/.rvm/gems/ree-1.8.7-2010.01%tdt/gems/hirb-0.2.10/lib/hirb/helpers/table/resizer.rb:30:in `select'
/Users/jlippiner/.rvm/gems/ree-1.8.7-2010.01%tdt/gems/hirb-0.2.10/lib/hirb/helpers/table/resizer.rb:30:in `adjust_long_fields'
/Users/jlippiner/.rvm/gems/ree-1.8.7-2010.01%tdt/gems/hirb-0.2.10/lib/hirb/helpers/table/resizer.rb:20:in `resize'
/Users/jlippiner/.rvm/gems/ree-1.8.7-2010.01%tdt/gems/hirb-0.2.10/lib/hirb/helpers/table/resizer.rb:7:in `resize!'
/Users/jlippiner/.rvm/gems/ree-1.8.7-2010.01%tdt/gems/hirb-0.2.10/lib/hirb/helpers/table.rb:244:in `setup_field_lengths'
/Users/jlippiner/.rvm/gems/ree-1.8.7-2010.01%tdt/gems/hirb-0.2.10/lib/hirb/helpers/table.rb:191:in `render'
/Users/jlippiner/.rvm/gems/ree-1.8.7-2010.01%tdt/gems/hirb-0.2.10/lib/hirb/helpers/table.rb:103:in `render'
/Users/jlippiner/.rvm/gems/ree-1.8.7-2010.01%tdt/gems/hirb-0.2.10/lib/hirb/helpers/object_table.rb:12:in `render'
/Users/jlippiner/.rvm/gems/ree-1.8.7-2010.01%tdt/gems/hirb-0.2.10/lib/hirb/helpers/active_record_table.rb:20:in `render'
/Users/jlippiner/.rvm/gems/ree-1.8.7-2010.01%tdt/gems/hirb-0.2.10/lib/hirb/views/activerecord_base.rb:7:in `render'
/Users/jlippiner/.rvm/gems/ree-1.8.7-2010.01%tdt/gems/hirb-0.2.10/lib/hirb/formatter.rb:137:in `format_output'
/Users/jlippiner/.rvm/gems/ree-1.8.7-2010.01%tdt/gems/hirb-0.2.10/lib/hirb/view.rb:154:in `render_output'
/Users/jlippiner/.rvm/gems/ree-1.8.7-2010.01%tdt/gems/hirb-0.2.10/lib/hirb/view.rb:71:in `view_output
Strange about 1.9.1. Works fine for me.
As for 1.8.7, the stacktrace still points to a possible Rational#to_f bug. Without a failing test case, I can't confirm this exists outside of 1.8.7.
If a model has too many attributes, you get this when using Hirb and running queries (i.e. Model.all) against that model.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rational.rb:390: warning: Bignum out of Float range
If I shut off Hirb this message does not appear.