www.SmarteGuru.com
  Home  |  Blogs  |  Find a Friend  |  Discussion Board  |  Resources   |  Developers Area  |  Gallery  |   Login  |  Register Now 

Why do I get “undefined method ’size’ for Float” warnings?

Are you using AJAX? Maybe an in-place text editor? Or one of those fancy “click the star to rate this” jobbers? Or see result of arithmetic calculation. It was that latter case for me.

@tatal_payable = (@total_event_payable.to_f - @coupon.value.to_f)
render_text @tatal_payable and return

where the @tatal_payable was a Float. Rails gave this strange error message:

A NoMethodError occurred in something#rate:

undefined method `size’ for 7160.0:Float

#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/cgi_process.rb:228:in `set_content_length!'
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/cgi_process.rb:187:in `out'
#{RAILS_ROOT}/vendor/gems/rails-1.2.3/lib/dispatcher.rb:41:in `dispatch'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:76:in `process'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:74:in `synchronize'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:74:in `process'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:159:in `process_client'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in `process_client'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `initialize'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `new'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in `initialize'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in `new'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:282:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:281:in `each'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:281:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:128:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/command.rb:212:in `run'
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:281
#{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:488:in `load'
#{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:488:in `load'
#{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in'
#{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:488:in `load'
#{RAILS_ROOT}/vendor/rails/railties/lib/commands/servers/mongrel.rb:60
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
#{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:495:in `require'
#{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in'
#{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:495:in `require'
#{RAILS_ROOT}/vendor/rails/railties/lib/commands/server.rb:39
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
script/server:3

So in that cgi_process.rb code, it has a variable called @body (the body of what’s being rendered back to the client) and it calls #size on it to set the content length header. It expects the body to be a String, reasonable so. So the issue is that we were passing a Float to “render :text”. Simply adding .to_s to the end of our float fixed the problem. Hope this saves you some time!

Social Bookmarks: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit
  • Webnews
  • Y!GG
  • Google Bookmarks
  • SEOigg
  • YahooMyWeb
  • Live-MSN
  • DZone
  • Facebook
  • Technorati
  • Ask
  • Furl
  • Spurl
  • Webbrille

Related Posts

Tags: , , , , , ,

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Viewed: 164 views

Leave a Reply

Home - About Us - Help - Terms and Conditions - Site Map - Link to Us - Resources - Contact Us
Google Rank Calculator | Suggest developer resource | Suggest Article
All rights reserved © 2007 SmarteGuru.com.