This project is archived and is in readonly mode.

#6482 ✓duplicate
Hans Engel

ActiveRecord: PostgreSQL floats returned as Strings; SQLite floats returned as floats

Reported by Hans Engel | February 27th, 2011 @ 04:23 PM

I've been working on a Rails app and just switched over to PostgreSQL for use on Heroku. The view for the index of my site calls the round method for some float values returned from the database. This worked fine when I was using SQLite — ActiveRecord returned Ruby Floats for columns that held float values in the database. I switched to PostgreSQL and got this error, however, after migrating / seeding the database and visiting the homepage:

2011-02-27T08:14:00-08:00 app[web.1]: ActionView::Template::Error (undefined method `round' for "86.0000000000000000":String):
2011-02-27T08:14:00-08:00 app[web.1]:     16:       %tr
2011-02-27T08:14:00-08:00 app[web.1]:     17:           %td= link_to p[0].layout + " / " + p[0].keyboard, :controller => 'profiles', :action => 'view', :id => p[0].id
2011-02-27T08:14:00-08:00 app[web.1]:     18:           %td= p[1]
2011-02-27T08:14:00-08:00 app[web.1]:     19:           %td= p[2].round
2011-02-27T08:14:00-08:00 app[web.1]:     20:           %td= p[3].round
2011-02-27T08:14:00-08:00 app[web.1]:   app/views/home/index.haml:19:in `_app_views_home_index_haml__1618257786_23737684188900_0'
2011-02-27T08:14:00-08:00 app[web.1]:   app/views/home/index.haml:15:in `each'
2011-02-27T08:14:00-08:00 app[web.1]:   app/views/home/index.haml:15:in `_app_views_home_index_haml__1618257786_23737684188900_0'

I'm guessing this is a bug in how ActiveRecord handles PostgreSQL data types?

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages