# Using URL path in REST app as ID

**URL:** <https://www.ruby-forum.com/t/using-url-path-in-rest-app-as-id/174194>\
**Category:** Rails\
**Created:** [August 22, 2009, 8:02am UTC](https://www.ruby-forum.com/t/using-url-path-in-rest-app-as-id/174194 "2009-08-22T08:02:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_Bennett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cab0a1/32.png) [@Jonathan\_Bennett](https://www.ruby-forum.com/u/Jonathan_Bennett)\
**Post date:** [August 22, 2009, 8:02am UTC](https://www.ruby-forum.com/t/using-url-path-in-rest-app-as-id/174194/1 "2009-08-22T08:02:33Z")

</div>

I’m a Rails newbie, so please bear with me. I want to use the URL as the  
ID for a RESTful resource, but using the path after the controller. The  
remaining portion of the URL would be the ID, rather than an integer.

So rather than just:

[http://example.org/widgets/1](http://example.org/widgets/1)

I want to use:

[http://example.org/widgets/foo](http://example.org/widgets/foo)  
[http://example.org/widgets/foo/bar](http://example.org/widgets/foo/bar)  
[http://example.org/widgets/foo/bar/baz](http://example.org/widgets/foo/bar/baz)

where foo, foo/bar and foo/bar/baz are all Widgets, not nested  
resources.

In the controller I’d like to do something like

@widget = Widget.find(params[:path])

where path is a string column defined as a primary key (or unique)  
containing strings like ‘foo’, ‘foo/bar’ and ‘foo/bar/baz’

Is this possible?

---

<div class="post-metadata">

**Author:** ![Jonathan\_Bennett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cab0a1/32.png) [@Jonathan\_Bennett](https://www.ruby-forum.com/u/Jonathan_Bennett)\
**Post date:** [August 22, 2009, 8:32am UTC](https://www.ruby-forum.com/t/using-url-path-in-rest-app-as-id/174194/2 "2009-08-22T08:32:58Z")

</div>

Jonathan Bennett wrote:

> I’m a Rails newbie, so please bear with me. I want to use the URL as the  
> ID for a RESTful resource, but using the path after the controller. The  
> remaining portion of the URL would be the ID, rather than an integer.
> 
> So rather than just:
> 
> [http://example.org/widgets/1](http://example.org/widgets/1)
> 
> I want to use:
> 
> [http://example.org/widgets/foo](http://example.org/widgets/foo)  
> [http://example.org/widgets/foo/bar](http://example.org/widgets/foo/bar)  
> [http://example.org/widgets/foo/bar/baz](http://example.org/widgets/foo/bar/baz)
> 
> where foo, foo/bar and foo/bar/baz are all Widgets, not nested  
> resources.
> 
> In the controller I’d like to do something like
> 
> @widget = Widget.find(params[:path])
> 
> where path is a string column defined as a primary key (or unique)  
> containing strings like ‘foo’, ‘foo/bar’ and ‘foo/bar/baz’
> 
> Is this possible?

Use permalink\_fu. I have used it in my free open source craigslist  
clone. To see how i have used it, you can download the entire  
application @ [http://www.classifiedscript.in](http://www.classifiedscript.in)
