routing requirements quick question

Hi everyone, first e-mail here :slight_smile:

I have the following in my routes.rb file.

map.connect 'posts/index/:page',
            :controller => 'posts',
            :action => 'index',
            :requirements => {:page => /\d+/ },
            :page => nil
end

Does :requirements => {:page => /\d+/ } mean that if the :page
parameter is empty this rule should not work?

Thanks in advance!

Yup! You probably want two routes:

map.connect 'posts/index/:page',
            :controller => 'posts',
            :action => 'index',
            :requirements => {:page => /\d+/ }

map.connect 'posts/index',
            :controller => 'posts',
            :action => 'index',
            :page => nil

Or more succinctly:

map.with_options(:controller => 'posts', :action => 'index') do |post_index|
   post_index.connect 'posts/index/:page', :requirements => {:page => /\d+/}
   post_index.connect 'posts/index', :page => nil
end

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com