开发者

How does path_prefix and requirements in Rails routes work?

开发者 https://www.devze.com 2023-01-11 04:43 出处:网络
Taking the 2 examples below - how do 开发者_JAVA百科they work? map.resources :api_developers, :path_prefix => \'-\'

Taking the 2 examples below - how do 开发者_JAVA百科they work?

map.resources :api_developers, :path_prefix => '-'

map.connect '-/:controller/:action/:id', :requirements => { :controller => /metrics|labs/ }


The :path_prefix option lets you add additional parameters that will be prefixed to the recognized paths. For example, suppose each photo in your application belongs to a particular photographer. In that case, you might declare this route:

map.resources :photos, :path_prefix => '/photographers/:photographer_id'

Routes recognized by this entry would include:

/photographers/1/photos/2
/photographers/1/photos

So yours samples

first one

/-/api_developers/
/-/api_developers/1
/-/api_developers/1/edit

etc

second one

/-/metrics/:action/:id
/-/labs/:action/:id

since there is no requirements on :action and :id they can be any string like

/-/metrics/first_string/second_string
0

精彩评论

暂无评论...
验证码 换一张
取 消