# Converting Number into Integer in ruby

**URL:** <https://www.ruby-forum.com/t/converting-number-into-integer-in-ruby/164816>\
**Category:** Rails\
**Created:** [April 6, 2009, 10:10am UTC](https://www.ruby-forum.com/t/converting-number-into-integer-in-ruby/164816 "2009-04-06T10:10:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vaibhav\_darji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a4c791/32.png) [@vaibhav\_darji](https://www.ruby-forum.com/u/vaibhav_darji)\
**Post date:** [April 6, 2009, 10:10am UTC](https://www.ruby-forum.com/t/converting-number-into-integer-in-ruby/164816/1 "2009-04-06T10:10:24Z")

</div>

I am working with a legacy oracle database. The  
primary key is not defined as an integer but as a number.  
This results in a url with an id as a number, such as 1234.0 instead  
of 1234. It works fine, but I would prefer 1234 to be displayed in  
the url. I have attempted to redefine the model id method to  
convert to an integer using to\_i method, but no luck. Any ideas?

Thanks,  
Vaibhav

---

<div class="post-metadata">

**Author:** ![vaibhav\_darji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a4c791/32.png) [@vaibhav\_darji](https://www.ruby-forum.com/u/vaibhav_darji)\
**Post date:** [April 6, 2009, 10:50am UTC](https://www.ruby-forum.com/t/converting-number-into-integer-in-ruby/164816/2 "2009-04-06T10:50:50Z")

</div>

On Apr 6, 9:10 am, Vaibhav Deshpande \<rails-mailing-l…@andreas-  
[s.net](http://s.net)\> wrote:

> I am working with a legacy oracle database. The  
> primary key is not defined as an integer but as a number.  
> This results in a url with an id as a number, such as 1234.0 instead  
> of 1234. It works fine, but I would prefer 1234 to be displayed in  
> the url.

The thing used for urls etc. is the to\_param method, you may have more  
luck doing your coercing there.

Fred

---

<div class="post-metadata">

**Author:** ![vaibhav\_darji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a4c791/32.png) [@vaibhav\_darji](https://www.ruby-forum.com/u/vaibhav_darji)\
**Post date:** [April 6, 2009, 11:28am UTC](https://www.ruby-forum.com/t/converting-number-into-integer-in-ruby/164816/3 "2009-04-06T11:28:45Z")

</div>

Frederick C. wrote:

> On Apr 6, 9:10?am, Vaibhav Deshpande \<rails-mailing-l…@andreas-  
> [s.net](http://s.net)\> wrote:
> 
> > I am working with a legacy oracle database. The  
> > primary key is not defined as an integer but as a number.  
> > This results in a url with an id as a number, such as 1234.0 instead  
> > of 1234. It works fine, but I would prefer 1234 to be displayed in  
> > the url.
> 
> The thing used for urls etc. is the to\_param method, you may have more  
> luck doing your coercing there.
> 
> Fred

You should be more spacific…  
I contain oracle as my database  
having table “oratest11”,contails 2 fields as  
(id\_field(Number),data(varchar2(20)) a sequence as “oratest11\_seq” which  
is incrementing the value of id\_field

My model is as follows:-

class Oratest11 \< ActiveRecord::Base  
set\_table\_name ‘oratest11’  
set\_primary\_key ‘id\_field’  
end

My Controler is as follows:-

class Oratest11sController \< ApplicationController  
def index  
@oratest11s=Oratest11.find(:all)  
end

def show  
@oratest11=Oratest11.find(params[:id])  
end

Index view:-

 \<% for ora in @oratest11s %\> 

```
    <td><%=h ora.data %>
  </td>

```

\<% end %\>

| \<%=h ora.id\_field %\> | \<%= link\_to 'show',:action=\>'show',:id=\>ora %\> |

Show View:-

| \<%= @oratest11.data %\> | \<%= @oratest11.id\_field %\> |

When i click on the show hiperlink error comes:-

Template is missing  
Missing template oratest11s/show.erb in view path app/views

But when i used  
default:-  
[http://localhost:3000/oratest11s/show/1.0](http://localhost:3000/oratest11s/show/1.0)  
Instade Used:-  
[http://localhost:3000/oratest11s/show/1](http://localhost:3000/oratest11s/show/1)  
it works fine…

so what could i used and how to directly go, after clicking the “view”  
hiperlink:-  
[http://localhost:3000/oratest11s/show/1](http://localhost:3000/oratest11s/show/1)

when, i change datatype of id\_field as Number to Integer it works  
fine…  
but, i dont want to change the datatype of id\_field sence it contains  
lots of records.
