# Restful URLs fail to generate when id is not numeric

**URL:** <https://www.ruby-forum.com/t/restful-urls-fail-to-generate-when-id-is-not-numeric/192837>\
**Category:** Rails\
**Created:** [August 6, 2010, 7:52pm UTC](https://www.ruby-forum.com/t/restful-urls-fail-to-generate-when-id-is-not-numeric/192837 "2010-08-06T19:52:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![techy\_bolek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee59a6/32.png) [@techy\_bolek](https://www.ruby-forum.com/u/techy_bolek)\
**Post date:** [August 6, 2010, 7:52pm UTC](https://www.ruby-forum.com/t/restful-urls-fail-to-generate-when-id-is-not-numeric/192837/1 "2010-08-06T19:52:34Z")

</div>

I’m trying to work with an existing Oracle schema which of course does  
not follow the Rails conventions for table/column names or primary key  
types. I used Scaffold to get everything going. I got the table name and  
the column names set up and I can retrieve the records correctly.  
However I cannot get the RESTful URLs to work, for Show or Edit. I  
nailed it down to the issue with the identifier not being numeric. When  
I update the primary key column - which is VARCHAR2(32) - to contain  
integers then all URL issues disappear and I am able to Show, Edit and  
Update. But when I fall back the original values I get “XXX\_url failed  
to generate…” errors. Any ideas how to get around this?  
Tom

---

<div class="post-metadata">

**Author:** ![techy\_bolek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee59a6/32.png) [@techy\_bolek](https://www.ruby-forum.com/u/techy_bolek)\
**Post date:** [August 6, 2010, 9:50pm UTC](https://www.ruby-forum.com/t/restful-urls-fail-to-generate-when-id-is-not-numeric/192837/2 "2010-08-06T21:50:31Z")

</div>

Tomasz R. wrote:

> I’m trying to work with an existing Oracle schema which of course does  
> not follow the Rails conventions for table/column names or primary key  
> types. I used Scaffold to get everything going. I got the table name and  
> the column names set up and I can retrieve the records correctly.  
> However I cannot get the RESTful URLs to work, for Show or Edit. I  
> nailed it down to the issue with the identifier not being numeric. When  
> I update the primary key column - which is VARCHAR2(32) - to contain  
> integers then all URL issues disappear and I am able to Show, Edit and  
> Update. But when I fall back the original values I get “XXX\_url failed  
> to generate…” errors. Any ideas how to get around this?  
> Tom

Is it possible that you’re existing primary key values will need to be  
URL escaped in order to produce valid URLs? Do they contain spaces or  
other special characters that are not permitted in URLs?

---

<div class="post-metadata">

**Author:** ![techy\_bolek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee59a6/32.png) [@techy\_bolek](https://www.ruby-forum.com/u/techy_bolek)\
**Post date:** [August 6, 2010, 8:12pm UTC](https://www.ruby-forum.com/t/restful-urls-fail-to-generate-when-id-is-not-numeric/192837/3 "2010-08-06T20:12:04Z")

</div>

On Fri, Aug 6, 2010 at 10:52 AM, Tomasz R.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m trying to work with an existing Oracle schema which of course does  
> not follow the Rails conventions for table/column names or primary key  
> types. I used Scaffold to get everything going. I got the table name and  
> the column names set up and I can retrieve the records correctly.  
> However I cannot get the RESTful URLs to work, for Show or Edit. I  
> nailed it down to the issue with the identifier not being numeric. When  
> I update the primary key column - which is VARCHAR2(32) - to contain  
> integers then all URL issues disappear and I am able to Show, Edit and  
> Update. But when I fall back the original values I get “XXX\_url failed  
> to generate…” errors.

Without any code, it’s hard to say. However, I have a legacy DB I’m  
working with that has an alphanumeric primary key, where the model  
includes:

set\_primary\_key “product” # e.g. “E70211A”

and this link generates an appropriate path:

\<%= link\_to product.product\_name, product\_path(product.product) %\>

## HTH,

Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![techy\_bolek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee59a6/32.png) [@techy\_bolek](https://www.ruby-forum.com/u/techy_bolek)\
**Post date:** [August 7, 2010, 2:30am UTC](https://www.ruby-forum.com/t/restful-urls-fail-to-generate-when-id-is-not-numeric/192837/4 "2010-08-07T02:30:43Z")

</div>

> Is it possible that you’re existing primary key values will need to be  
> URL escaped in order to produce valid URLs? Do they contain spaces or  
> other special characters that are not permitted in URLs?

Yup! Thanks! That’s what it was! I had a few entries formatted like:  
XXX.DEFAULT.USER.834029834092830

I changed the primary key and it worked. Will figure out later how to  
handle it long-term.

Robert W. wrote:

> Tomasz R. wrote:
> 
> > I’m trying to work with an existing Oracle schema which of course does  
> > not follow the Rails conventions for table/column names or primary key  
> > types. I used Scaffold to get everything going. I got the table name and  
> > the column names set up and I can retrieve the records correctly.  
> > However I cannot get the RESTful URLs to work, for Show or Edit. I  
> > nailed it down to the issue with the identifier not being numeric. When  
> > I update the primary key column - which is VARCHAR2(32) - to contain  
> > integers then all URL issues disappear and I am able to Show, Edit and  
> > Update. But when I fall back the original values I get “XXX\_url failed  
> > to generate…” errors. Any ideas how to get around this?  
> > Tom
> 
> Is it possible that you’re existing primary key values will need to be  
> URL escaped in order to produce valid URLs? Do they contain spaces or  
> other special characters that are not permitted in URLs?

---

<div class="post-metadata">

**Author:** ![techy\_bolek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee59a6/32.png) [@techy\_bolek](https://www.ruby-forum.com/u/techy_bolek)\
**Post date:** [August 6, 2010, 9:52pm UTC](https://www.ruby-forum.com/t/restful-urls-fail-to-generate-when-id-is-not-numeric/192837/5 "2010-08-06T21:52:45Z")

</div>

BTW for those that follow my posts, I’m actually not completely daft on  
the use of your vs. you’re, and its vs. it’s. I guess my fingers are  
when typing into this forum though. Grrr. I drive myself nuts with that  
sometimes. hehe.
