# Manual route redundancy with .:format (REST from scratch)

**URL:** <https://www.ruby-forum.com/t/manual-route-redundancy-with-format-rest-from-scratch/106756>\
**Category:** Rails\
**Created:** [June 13, 2007, 9:22pm UTC](https://www.ruby-forum.com/t/manual-route-redundancy-with-format-rest-from-scratch/106756 "2007-06-13T21:22:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [June 13, 2007, 9:22pm UTC](https://www.ruby-forum.com/t/manual-route-redundancy-with-format-rest-from-scratch/106756/1 "2007-06-13T21:22:19Z")

</div>

I am building an RESTful search application in Rails. Unfortunately I  
can’t take advantage of map.resources routing because the application  
has no models (it communicates with a SOAP service). So I am building  
a REST architecture from scratch.

I have 5 custom routes to emulate RESTful nesting of resources.  
However, I have to duplicate every entry to be able to catch whether  
or not the resource is requested with a format. So I have to have 10  
route entries…

map.connect ‘parent/:parentid/child/:childid.:format’,  
:controller =\> ‘child’,  
:action =\> ‘show’,  
:conditions =\> {:method =\> :get}

map.connect ‘parent/:parentid/child/:childid’,  
:controller =\> ‘child’,  
:action =\> ‘show’,  
:conditions =\> {:method =\> :get}

…

Does anybody have any suggestions on how I can set this up so I don’t  
repeat myself?

Cheers,  
Stephanie

---

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [June 13, 2007, 9:30pm UTC](https://www.ruby-forum.com/t/manual-route-redundancy-with-format-rest-from-scratch/106756/2 "2007-06-13T21:30:23Z")

</div>

On 6/13/07, stephanie [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am building an RESTful search application in Rails. Unfortunately I  
> can’t take advantage of map.resources routing because the application  
> has no models (it communicates with a SOAP service). So I am building  
> a REST architecture from scratch.

map.resources is not tightly bound to models (or the naming convention  
for controllers, as it happens)

map.resources :wibbles, :controller =\> ‘something\_arbitrary’

your something\_arbitrary\_controller.rb can do whatever it wants - it’s  
_your_ code.

HTH,  
Trevor

## –

Trevor S.  
[http://somethinglearned.com](http://somethinglearned.com)

---

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [June 13, 2007, 10:01pm UTC](https://www.ruby-forum.com/t/manual-route-redundancy-with-format-rest-from-scratch/106756/3 "2007-06-13T22:01:26Z")

</div>

Thanks for the reply. I used map.resources and it worked fine until I  
began nesting my resources. The syntax for nesting map.resources does  
not seem to work without models. The issue I have with map.resources  
is it creates several routes which aren’t applicable to my  
application. For instance, I have a few controllers which should only  
be accessible with a GET since they are results from a web service.  
The POST, PUT, DELETE + new and edit are not needed.

-Stephanie

---

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [June 13, 2007, 10:17pm UTC](https://www.ruby-forum.com/t/manual-route-redundancy-with-format-rest-from-scratch/106756/4 "2007-06-13T22:17:30Z")

</div>

On 6/13/07, stephanie [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks for the reply. I used map.resources and it worked fine until I  
> began nesting my resources. The syntax for nesting map.resources does  
> not seem to work without models. The issue I have with map.resources

I’m not sure how it wouldn’t work without models - as I said,  
map.resources has nothing to do with models really.

I’ll hazard a guess tho: is it something like you want /foo  
(foo\_controller) and /foo/bar (bar\_controller)? If that’s what you’re  
talking about, then /foo is a map.resource (note the singular).

So unless what I’ve said above (or what _you_ said below) explains why  
it doesn’t work for you, maybe you could expand on this a bit?

> is it creates several routes which aren’t applicable to my  
> application. For instance, I have a few controllers which should only  
> be accessible with a GET since they are results from a web service.  
> The POST, PUT, DELETE + new and edit are not needed.

Yeah, I can understand why you wouldn’t want them. I guess it’s a  
tradeoff between the convenience of map.resources with a controller  
that only has index/show methods vs the extra (and un-used) routes and  
url helpers.

If the extra routes and helpers really offend you then you could whip  
up a little helper or two that generates routes the way you want -  
after all, that’s what map.resources is (see resources.rb in the rails  
source).

HTH,  
Trevor

## –

Trevor S.  
[http://somethinglearned.com](http://somethinglearned.com)

---

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [June 13, 2007, 10:07pm UTC](https://www.ruby-forum.com/t/manual-route-redundancy-with-format-rest-from-scratch/106756/5 "2007-06-13T22:07:28Z")

</div>

stephanie wrote:

> Thanks for the reply. I used map.resources and it worked fine until I  
> began nesting my resources. The syntax for nesting map.resources does  
> not seem to work without models. The issue I have with map.resources  
> is it creates several routes which aren’t applicable to my  
> application. For instance, I have a few controllers which should only  
> be accessible with a GET since they are results from a web service.  
> The POST, PUT, DELETE + new and edit are not needed.

I’m curious why this would be a problem? If you don’t define the  
corresponding methods in your controller you should be fine? Or am I  
missing something?

–  
Cheers,

- Jacob A.

---

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [June 13, 2007, 11:27pm UTC](https://www.ruby-forum.com/t/manual-route-redundancy-with-format-rest-from-scratch/106756/6 "2007-06-13T23:27:42Z")

</div>

Thanks, this discussion has been really helpful.

I am not sure why it didn’t work when I nested it. Perhaps it has to  
do with mapping associations in the resources.rb. It was awhile ago,  
so there might have been singular issue. At this point I think I’ve  
decided I want to implement my own routes. I might refer to  
resources.rb to create my own helper.

Rails map.resources is a great template for how I’d want to do RESTful  
routes 95% of the time. However, there are times when the conventions  
breakdown for a particular resource-oriented service.

-Stephanie
