# Routes.rb

**URL:** <https://www.ruby-forum.com/t/routes-rb/193415>\
**Category:** Rails\
**Created:** [August 17, 2010, 12:00pm UTC](https://www.ruby-forum.com/t/routes-rb/193415 "2010-08-17T12:00:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [August 17, 2010, 12:00pm UTC](https://www.ruby-forum.com/t/routes-rb/193415/1 "2010-08-17T12:00:52Z")

</div>

Hello All,

In routes.rb, to create and access a new page everytime i need to write  
:page\_name =\> :any to my config/routes.rb.  
Can you guys tell me any better alternative to this?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [August 17, 2010, 2:25pm UTC](https://www.ruby-forum.com/t/routes-rb/193415/2 "2010-08-17T14:25:02Z")

</div>

On 17 Aug 2010, at 11:00, Hemant B. wrote:

> In routes.rb, to create and access a new page everytime i need to write  
> :page\_name =\> :any to my config/routes.rb.  
> Can you guys tell me any better alternative to this?

I’m not 100% sure I understoon what you’re after but take a look at:

[Rails Routing from the Outside In — Ruby on Rails Guides](http://guides.rubyonrails.org/routing.html). Specifically section 4.9 on  
route globbing.

or

[Rails Routing from the Outside In — Ruby on Rails Guides](http://edgeguides.rubyonrails.org/routing.html). Section 3.10.

Cheers,  
Jim

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [August 17, 2010, 3:40pm UTC](https://www.ruby-forum.com/t/routes-rb/193415/3 "2010-08-17T15:40:16Z")

</div>

Hemant B. wrote:

> In routes.rb, to create and access a new page everytime i need to write  
> :page\_name =\> :any to my config/routes.rb.

Why?

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [August 17, 2010, 3:58pm UTC](https://www.ruby-forum.com/t/routes-rb/193415/4 "2010-08-17T15:58:45Z")

</div>

On 17 August 2010 14:48, Hemant B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hope you people got it right… 🙂

So are you asking the question is there a better way do define the  
route for create\_req rather than specifying it as you have above? I  
don’t see how it could be much more concise.

Colin

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [August 17, 2010, 3:48pm UTC](https://www.ruby-forum.com/t/routes-rb/193415/5 "2010-08-17T15:48:33Z")

</div>

Ar Chron wrote:

> Hemant B. wrote:
> 
> > In routes.rb, to create and access a new page everytime i need to write  
> > :page\_name =\> :any to my config/routes.rb.

Ok. Here is the whole scenario for those who did’nt get it. I am using  
scaffolding type for resumes, portals, agencies etc etc. For portals and  
agencies i just defined map.resources :portals, :agencies and all seems  
to work fine.

I also have map.resources for resumes. Now my question is that if i add  
a new page(lets say create\_forward) i need to describe it like this in  
routes.rb,

map.resources :resumes, :collection =\> { :create\_forward }

and if i add a new page (create\_req) then i need to define it in  
routes.rb as,

map.resources :resumes, :collection =\> { :create\_req }

Hope you people got it right… 🙂

> Why?

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [August 17, 2010, 4:06pm UTC](https://www.ruby-forum.com/t/routes-rb/193415/6 "2010-08-17T16:06:05Z")

</div>

Hemant B. wrote:

> I also have map.resources for resumes. Now my question is that if i add  
> a new page(lets say create\_forward) i need to describe it like this in  
> routes.rb,
> 
> map.resources :resumes, :collection =\> { :create\_forward }
> 
> and if i add a new page (create\_req) then i need to define it in  
> routes.rb as,
> 
> map.resources :resumes, :collection =\> { :create\_req }

Oh, so each time you want Rails to respond to a new method for either  
the collection, or a member of the collection you have to specify those  
additional methods in your routes.rb file?

Well, yes, that’s all part of using restful routing in Rails. In terms  
of clarity and ease of maintenance, I haven’t found a better way.

You could go backwards and use non-restful routing, but that’s actually  
more work, or you rely on default routes (yuck) to try and match-up  
routes to controllers, actions and ids.

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [August 17, 2010, 4:08pm UTC](https://www.ruby-forum.com/t/routes-rb/193415/7 "2010-08-17T16:08:51Z")

</div>

Colin L. wrote:

> On 17 August 2010 14:48, Hemant B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Hope you people got it right… 🙂
> 
> So are you asking the question is there a better way do define the  
> route for create\_req rather than specifying it as you have above? I  
> don’t see how it could be much more concise.

Yeah i asked for the better way because i have created so many pages. So  
for each page i have to write it as above. I mean suppose i create 10  
pages then each time i have to write as:

map.resources :resumes, :collection =\> { :create\_req =\> :any,  
:page1 =\> :any,  
:page2 =\> :any,  
…  
…  
:page10 =\> :any }  
So the lines of code becomes large and messy as well. Is’nt there a  
single/two liner for this?

> Colin

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [August 17, 2010, 4:23pm UTC](https://www.ruby-forum.com/t/routes-rb/193415/8 "2010-08-17T16:23:15Z")

</div>

Hemant B. wrote:

> Colin L. wrote:
> 
> > On 17 August 2010 14:48, Hemant B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> > 
> > > Hope you people got it right… 🙂
> > 
> > So are you asking the question is there a better way do define the  
> > route for create\_req rather than specifying it as you have above? I  
> > don’t see how it could be much more concise.
> 
> Yeah i asked for the better way because i have created so many pages. So  
> for each page i have to write it as above. I mean suppose i create 10  
> pages then each time i have to write as:
> 
> map.resources :resumes, :collection =\> { :create\_req =\> :any,  
> :page1 =\> :any,  
> :page2 =\> :any,  
> …  
> …  
> :page10 =\> :any }  
> So the lines of code becomes large and messy as well. Is’nt there a  
> single/two liner for this?

Sort of. You probably don’t want to use RESTful routing for this.  
Instead, you probably want something like

map.connect ‘resumes/:page’, :controller =\> ‘resumes’, :action =\>  
‘some\_action’

…and then look at params[:page] in the controller.

> > Colin

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
