Form_for (or erb) is pulling floats instead of ints in ActiveRecord

form_for (or erb) is pulling floats instead of ints in ActiveRecord

My team is currently upgrading a rails app from 3.2.3 to 4.0 with JRuby
1.7.10 backed by Oracle. Under Rails 3.2.3 everything is nice and
happy…

We have a model called JobMetadata and every numeric column is an
integer (although Oracle does store them as Number(38). The database is
unchanged from 3.2.3 to 4.0.

Suppose I have an instance (of JobMetadata ) called jmd, and I reference
jmd.max_execution_time. jmd.max_execution_time.class is a FixNum ( in
4.0 – yay).

If I pull it out in erb (via form_for) it always pulls out a string
representation of a float like “60.0” in 4.0 (but “60” in 3.2.3).
For example:

<%= form_for(@job_metadata, :url => { :action => “update” }) do |f| %>
<%= f.text_field :max_execution_minutes, :size=>10%>

Would yield “60” in the text field in 3.2.3 but “60.0” in 4.0.
We “fixed” this issue via:

<%= f.text_field :max_execution_minutes, :size=>10, :value =>
f.object.max_execution_minutes %>

Such a fix makes us a little queasy, and the root of the problem was
waiting to haunt us in other ways…

When we attempt to hit the update page for our Jobmetadata via:

@job_metadata.update_attributes(params[:job_metadata])

It fails, why? Well our Jobmetadata model does have the following
relationship:

has_many :escalations, -> { order(“priority ASC”) }, {dependent:
:destroy}

When erb pulls out the index for our escalation this is what we see:

Note that the index is a float :-(. When we examine this value in
params via the debugger we also see this.

The update fails as it expects a FixNum for an ID.

Interestingly the ID for the Jobmetadata itself is an integer type
value. I suspect this is because it is yanked from the route.

I will also post this in the JRuby forum in case this is a JRuby issue.

Much thanks.

Cris

my Gem list is below:

*** LOCAL GEMS ***

actionmailer (4.0.0, 3.2.16, 3.2.3)
actionpack (4.0.0, 3.2.16, 3.2.3)
activemodel (4.0.0, 3.2.16, 3.2.3)
activerecord (4.0.0, 3.2.16, 3.2.3)
activerecord-deprecated_finders (1.0.3)
activerecord-jdbc-adapter (1.3.5)
activerecord-jdbcsqlite3-adapter (1.3.5)
activeresource (3.2.16, 3.2.3)
activesupport (4.0.0, 3.2.16, 3.2.3)
american_date (1.1.0)
arel (4.0.1, 3.0.3)
atomic (1.1.14 java)
bcrypt-ruby (3.1.2 java)
bouncy-castle-java (1.5.0147)
builder (3.1.4, 3.0.4)
bundler (1.5.2)
chronic (0.10.2)
coffee-rails (4.0.1, 3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.6.3)
devise (3.2.2, 2.2.8)
devise-encryptable (0.1.2)
erubis (2.7.0)
execjs (2.0.2)
gem_plugin (0.2.3)
hike (1.2.3)
hoe (3.8.1, 3.8.0)
i18n (0.6.9)
jbuilder (1.5.3)
jdbc-sqlite3 (3.7.2.1)
journey (1.0.4)
jquery-rails (3.0.4)
jruby-jars (1.7.10)
jruby-openssl (0.9.4, 0.9.3)
jruby-rack (1.1.13.3)
json (1.8.1 java, 1.8.0 java)
krypt (0.0.1)
krypt-core (0.0.1 universal-java)
krypt-provider-jdk (0.0.1)
linecache (0.46 java)
log4r (1.1.10)
mail (2.5.4, 2.4.4)
mime-types (1.25.1)
minitest (4.7.5)
multi_json (1.8.4)
orderedhash (0.0.6)
orm_adapter (0.5.0)
polyglot (0.3.3)
protected_attributes (1.0.3)
rack (1.5.2, 1.4.5)
rack-cache (1.2)
rack-ssl (1.3.3)
rack-test (0.6.2)
rails (4.0.0, 3.2.16, 3.2.3)
railties (4.0.0, 3.2.16, 3.2.3)
rake (10.1.1, 10.1.0)
rdoc (4.1.1, 4.0.1, 3.12.2)
ruby-debug-base (0.10.5.rc9 java)
ruby-debug-ide (0.4.22)
rubyzip (1.0.0)
sass (3.2.14, 3.2.13)
sass-rails (4.0.1, 3.2.6)
sdoc (0.4.0)
sprockets (2.10.1, 2.2.2, 2.1.3)
sprockets-rails (2.0.1)
therubyrhino (2.0.2)
therubyrhino_jar (1.7.4)
thor (0.18.1, 0.14.6)
thread_safe (0.1.3 java)
tilt (1.4.1)
treetop (1.4.15)
trinidad (1.4.6)
trinidad_jars (1.3.0)
turbolinks (2.2.0)
tzinfo (0.3.38)
uglifier (2.4.0)
warbler (1.4.0)
warden (1.2.3)
whenever (0.9.0)
will_paginate (3.0.5)