Forum: Ruby on Rails Converting Number into Integer in ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
84161f131a41bf1b730a7a4fbfd9068d?d=identicon&s=25 Vaibhav Deshpande (vaibhavdeshpandemca)
on 2009-04-06 10:10
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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-06 10:50
(Received via mailing list)
On Apr 6, 9:10 am, Vaibhav Deshpande <rails-mailing-l...@andreas-
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
84161f131a41bf1b730a7a4fbfd9068d?d=identicon&s=25 Vaibhav Deshpande (vaibhavdeshpandemca)
on 2009-04-06 11:28
Frederick Cheung wrote:
> On Apr 6, 9:10?am, Vaibhav Deshpande <rails-mailing-l...@andreas-
> 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:-

<table>
  <% for ora in @oratest11s %>
    <tr>

        <td><%=h ora.data %>
      </td>
<td><%=h ora.id_field %>
      </td>
       <td><%= link_to 'show',:action=>'show',:id=>ora %></td>
    </tr>

  <% end %>

</table>


Show View:-

<table border="1">
  <tr>
    <td><%= @oratest11.data %>
    </td>
     <td><%= @oratest11.id_field %>
    </td>

  </tr>
</table>


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
Instade Used:-
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


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.
This topic is locked and can not be replied to.