Routes.rb

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.

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

http://guides.rubyonrails.org/routing.html. Specifically section 4.9 on route globbing.

or

http://edgeguides.rubyonrails.org/routing.html. Section 3.10.

Cheers,
Jim

Hemant Bhargava 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?

Ar Chron wrote:

Hemant Bhargava 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.. :slight_smile:

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

Hemant Bhargava 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.

Colin Law wrote:

Hope you people got it right.. :slight_smile:

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?

Hemant Bhargava wrote:

Colin Law wrote:

Hope you people got it right.. :slight_smile:

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,