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.
Don M. (Guest)
on 2005-12-12 18: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
Jeffrey H. (Guest)
on 2005-12-12 20: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
Don M. (Guest)
on 2005-12-13 17:11
Thanks Jeff,
Don


Jeffrey H. 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.