How do we identify parameters in a dynamic URL?

前端 未结 2 779
别那么骄傲
别那么骄傲 2021-01-16 12:11

We are building a Rails CMS where a blog or news listing can appear anywhere in the site tree. This means that any page knows their type based on a database field - eg: a p

2条回答
  •  忘掉有多难
    2021-01-16 12:31

    You can configure this issue in your routes.rb file.

    you can add a route like

     map.connect 'snoopy-news/:year/:date', :controller => 'needed controller', :action => 'needed action' 

    this will route any URL of the format

     ../snoopy-news/2010/23 
    to the corresponding controller and action with the values set in the varialbles
     year , date 

    If you dont give anything, RAILS will consider this as a parameter.

提交回复
热议问题