# Unwanted RESTful routes

**URL:** <https://www.ruby-forum.com/t/unwanted-restful-routes/139329>\
**Category:** Rails\
**Created:** [June 2, 2008, 11:34pm UTC](https://www.ruby-forum.com/t/unwanted-restful-routes/139329 "2008-06-02T23:34:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![daz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@daz](https://www.ruby-forum.com/u/daz)\
**Post date:** [June 2, 2008, 11:34pm UTC](https://www.ruby-forum.com/t/unwanted-restful-routes/139329/1 "2008-06-02T23:34:22Z")

</div>

Hi,

In my app, I’ve got a Page model and in my routes.rb have the line:

map.resources :pages

This gives me all of the nice urls for all of the CRUD actions.  
However, for showing pages, I didn’t like the urls pages/5 wasn’t very  
descriptive. I preferered ‘nice’ urls such as blog/about-me. I could  
use the to\_params method to specify using permalinks instead, but you  
still had to put pages/ in front of the permalink and I couldn’t find  
a way to avoid having the model name at the start of urls.

I’ve come up with a route that solves this problem and people can  
access the pages using this ‘nice’ notation and I can generate it  
using the helper nice\_page\_path(@page).

But since I don’t actually use the page\_path(@page) helper it would be  
nice if I could use this to generate my ‘nice’ paths instead of having  
a custom helper called nice\_page\_path. Is there an option you can pass  
to map.resources to say that you don’t want one of the routes? Or is  
there a way of overriding this helper so I can use it for my paths  
instead?

thanks,

DAZ

---

<div class="post-metadata">

**Author:** ![daz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@daz](https://www.ruby-forum.com/u/daz)\
**Post date:** [June 3, 2008, 2:18am UTC](https://www.ruby-forum.com/t/unwanted-restful-routes/139329/2 "2008-06-03T02:18:22Z")

</div>

> But since I don’t actually use the page\_path(@page) helper it would be  
> nice if I could use this to generate my ‘nice’ paths instead of having  
> a custom helper called nice\_page\_path. Is there an option you can pass  
> to map.resources to say that you don’t want one of the routes? Or is  
> there a way of overriding this helper so I can use it for my paths  
> instead?

You might think it would be nice, but it sort of defeats the one of the  
purposes of REST, which is for all sites to follow a standard for the  
basic 7 actions. If you have a route that works the way you want it to,  
and a helper that produces the url’s the way you want it to, why do you  
feel you need to wreck/disable the standard RESTful actions and the rest  
of the world’s RESTful access to your site content? As long as they can  
get your content with “pretty” url’s when they want to, is there really  
a problem with people/programs still being able to reach your content  
via “/pages/5”?

---

<div class="post-metadata">

**Author:** ![daz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@daz](https://www.ruby-forum.com/u/daz)\
**Post date:** [June 3, 2008, 8:56am UTC](https://www.ruby-forum.com/t/unwanted-restful-routes/139329/3 "2008-06-03T08:56:45Z")

</div>

That’s a good point Cayce, thanks. I was thinking of keeping both ways  
of accessing the pages and now you’ve helped to convince me that I  
should keep that convention in place.

I still think that using permalinks such as /blog/about-me is much  
more descriptive than pages/5 and also think that in this one case a  
‘pages’ model is one where you wouldn’t want the url to be preceded by  
the word ‘pages’. I can certainly understand why you would in other  
cases - ‘products’, ‘episodes’ etc, but it is usually taken as a given  
that what you are looking at is a page (although maybe not when we are  
supposed to be assuming that everything is a resource…)

Thanks again,

DAZ

On Jun 3, 1:18 am, Cayce B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![daz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@daz](https://www.ruby-forum.com/u/daz)\
**Post date:** [June 4, 2008, 2:17pm UTC](https://www.ruby-forum.com/t/unwanted-restful-routes/139329/4 "2008-06-04T14:17:35Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

On Tuesday 03 June 2008 02:18:22 Cayce B. wrote:

> You might think it would be nice, but it sort of defeats the one of  
> the purposes of REST, which is for all sites to follow a standard for  
> the basic 7 actions.

Uniforum naming of actions and objects is a popular goal of many people,  
but not a purpose of REST.

Ciao,  
Sheldon.  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIRoelpGJX8XSgas0RAhjYAKCJdIcX4ot3dMWT7kx3urkha0yzFwCglXdE  
G/VHU/Emzry9GjKNQ8rLI3Y=  
=ETPj  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![daz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@daz](https://www.ruby-forum.com/u/daz)\
**Post date:** [June 4, 2008, 2:26pm UTC](https://www.ruby-forum.com/t/unwanted-restful-routes/139329/5 "2008-06-04T14:26:35Z")

</div>

Thanks for clearing that up Sheldon. Like I said already, having names  
like /blog/about-me makes more sense in this case because it also give  
information about the parent page (blog) of the page being found  
(about-me), so adds some scope to the url that you wouldn’t get from /  
pages/5.

I’m in two minds here - should I allow both urls as some people might  
expect the ‘convention’ of /pages/5 or should I try to keep things  
like the id of the page private to the application?

Also, with regard to my original question, is it possible to EXCLUDE  
some of the helpers from map.resources? Should it be possible? If not  
and this isn’t the purpose of REST then why force this style of url?

cheers,

DAZ

---

<div class="post-metadata">

**Author:** ![daz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@daz](https://www.ruby-forum.com/u/daz)\
**Post date:** [June 4, 2008, 5:07pm UTC](https://www.ruby-forum.com/t/unwanted-restful-routes/139329/6 "2008-06-04T17:07:34Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

On Wednesday 04 June 2008 14:26:13 DAZ wrote:

> I’m in two minds here - should I allow both urls as some people might  
> expect the ‘convention’ of /pages/5 or should I try to keep things  
> like the id of the page private to the application?

That’s hard for me to answer, because I can’t imagine a situation in  
which an outside consumer of your web service could possibly know that  
it’s interested in doing something with page 5, without already knowing  
enough about page 5 to know that its slug is about-me. 🙂

That said, the existence of the unpublished routes isn’t hurting you.

> Also, with regard to my original question, is it possible to EXCLUDE  
> some of the helpers from map.resources?

No. The whole point of ActionController::Resources#resources is to map  
routes to a “RESTful resource”. That has specific meaning, and  
includes things like: if you GET /page/5, I’ll route you to the  
PageController’s show action, passing it an id parameter of 5.

Perhaps the confusion here comes from people collapsing the term REST  
with the term RESTful resource.

If you don’t want to implement RESTful resources, don’t use  
ActionController::Resources#resources to map routes.

But again, they’re not hurting you.

Personally, I don’t mind pretty URLs when someone else implements them  
in software I use (e.g. Mephisto Blog), but I never implement them  
myself. I think they’re pointless, particularly in the kinds of  
applications I write.

Ciao,  
Sheldon.  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIRq9wpGJX8XSgas0RAj1FAJ9+A3VoEndvlw+aKuJ6FB62Q5DGngCfeJXw  
/XHWHwIB36PkLgk/l/NejZQ=  
=YH+Y  
-----END PGP SIGNATURE-----
