Forum: Ruby on Rails How to convert url /contr../action/6.0 to /cont../action/6 ?

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.
Aeac27d9f81191536d3c86ee825d71b2?d=identicon&s=25 Don Mc (dmcclean)
on 2005-12-12 17:41
I am using a legacy db which has the column for the
primary key defined as a decimal number rather than
an integer, even though only integer values are stored
in in.

  When rails generates a url it is of the form
  /controller/action/123.0

This works, but I would prefer

  /controller/action/123

What would be the best way to automatically force the
convesion to integers? I have attempted to
redefined the 'id' method in the model to convert
the value to an integer, but this does not work.

Thanks in advance,
donmc
2c945de84229ee29abb9aaa484b44c57?d=identicon&s=25 Jeffrey Hardy (Guest)
on 2005-12-12 19:40
(Received via mailing list)
On 12-Dec-05, at 11:41 AM, don mc wrote:
>   /controller/action/123
>
> What would be the best way to automatically force the
> convesion to integers? I have attempted to
> redefined the 'id' method in the model to convert
> the value to an integer, but this does not work.

Try accessing the value before it's type casted. Example,

account.id_before_type_cast

/Jeff
Aeac27d9f81191536d3c86ee825d71b2?d=identicon&s=25 Don Mc (dmcclean)
on 2005-12-13 16:11
Thanks Jeff,
Don


Jeffrey Hardy wrote:
> On 12-Dec-05, at 11:41 AM, don mc wrote:
>>   /controller/action/123
>>
>> What would be the best way to automatically force the
>> convesion to integers? I have attempted to
>> redefined the 'id' method in the model to convert
>> the value to an integer, but this does not work.
>
> Try accessing the value before it's type casted. Example,
>
> account.id_before_type_cast
>
> /Jeff
This topic is locked and can not be replied to.