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 -- Posted via http://www.ruby-forum.com/.
Jeffrey Hardy
2005-Dec-12 18:37 UTC
Re: How to convert url /contr../action/6.0 to /cont../action/6 ?
On 12-Dec-05, at 11:41 AM, don mc wrote:> 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.Try accessing the value before it''s type casted. Example, account.id_before_type_cast /Jeff
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-- Posted via http://www.ruby-forum.com/.