Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#6482

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?

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

State: duplicate
Milestone: none
Assigned to: nobody
Importance: Low