routes.rb
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:6k
源码类别:

Ajax

开发平台:

Others

  1. ActionController::Routing::Routes.draw do |map|
  2.   # default
  3.   map.root :controller  => 'articles', :action => 'index'
  4.   # TODO: use only in archive sidebar. See how made other system
  5.   map.articles_by_month ':year/:month', :controller => 'articles', :action => 'index', :year => /d{4}/, :month => /d{1,2}/
  6.   map.articles_by_month_page ':year/:month/page/:page', :controller => 'articles', :action => 'index', :year => /d{4}/, :month => /d{1,2}/
  7.   map.articles_by_year ':year', :controller => 'articles', :action => 'index', :year => /d{4}/
  8.   map.articles_by_year_page ':year/page/:page', :controller => 'articles', :action => 'index', :year => /d{4}/
  9.   map.admin 'admin', :controller  => 'admin/dashboard', :action => 'index'
  10.   # make rss feed urls pretty and let them end in .xml
  11.   # this improves caches_page because now apache and webrick will send out the
  12.   # cached feeds with the correct xml mime type.
  13.   map.rss 'articles.rss', :controller => 'articles', :action => 'index', :format => 'rss'
  14.   map.atom 'articles.atom', :controller => 'articles', :action => 'index', :format => 'atom'
  15.   
  16.   map.with_options :controller => 'xml', :path_prefix => 'xml' do |controller|
  17.     controller.xml 'articlerss/:id/feed.xml', :action => 'articlerss'
  18.     controller.xml 'commentrss/feed.xml', :action => 'commentrss'
  19.     controller.xml 'trackbackrss/feed.xml', :action => 'trackbackrss'
  20.     
  21.     controller.with_options :action => 'feed' do |action|
  22.       action.xml 'rss', :type => 'feed', :format => 'rss'
  23.       action.xml 'sitemap.xml', :format => 'googlesitemap', :type => 'sitemap', :path_prefix => nil
  24.       action.xml ':format/feed.xml', :type => 'feed'
  25.       action.xml ':format/:type/feed.xml'
  26.       action.xml ':format/:type/:id/feed.xml'
  27.     end
  28.   end
  29.   
  30.   map.resources :comments, :name_prefix => 'admin_', :collection => [:preview]
  31.   map.resources :trackbacks
  32.   map.live_search_articles '/live_search/', :controller => "articles", :action => "live_search"
  33.   map.search '/search/:q.:format', :controller => "articles", :action => "search"
  34.   map.search_base '/search/', :controller => "articles", :action => "search"
  35.   map.connect '/archives/', :controller => "articles", :action => "archives"
  36.   map.connect '/setup', :controller => 'setup', :action => 'index'
  37.   map.connect '/setup/confirm', :controller => 'setup', :action => 'confirm'
  38.   
  39.   # I thinks it's useless. More investigating
  40.   map.connect "trackbacks/:id/:day/:month/:year",
  41.     :controller => 'trackbacks', :action => 'create', :conditions => {:method => :post}
  42.   # Before use inflected_resource
  43.   map.resources :categories, :except => [:show, :update, :destroy, :edit]
  44.   map.resources :categories, :as => 'category', :only => [:show, :edit, :update, :destroy]
  45.   map.connect '/category/:id/page/:page', :controller => 'categories', :action => 'show'
  46.   
  47.   # Before use inflected_resource
  48.   map.resources :tags, :except => [:show, :update, :destroy, :edit]
  49.   map.resources :tags, :as => 'tag', :only => [:show, :edit, :update, :destroy]
  50.   map.connect '/tag/:id/page/:page', :controller => 'tags', :action => 'show'
  51.   map.connect '/tags/page/:page', :controller => 'tags', :action => 'index'
  52.   map.connect '/author/:id', :controller => 'authors', :action => 'show'
  53.   map.xml '/author/:id.:format', :controller => 'authors', :action => 'show', :format => /rss|atom/
  54.   
  55.   # allow neat perma urls
  56.   map.connect 'page/:page',
  57.     :controller => 'articles', :action => 'index',
  58.     :page => /d+/
  59.   date_options = { :year => /d{4}/, :month => /(?:0?[1-9]|1[012])/, :day => /(?:0[1-9]|[12]d|3[01])/ }
  60.   map.with_options(:conditions => {:method => :get}) do |get|
  61.     get.connect 'pages/*name',:controller => 'articles', :action => 'view_page'
  62.     get.with_options(:controller => 'theme', :filename => /.*/, :conditions => {:method => :get}) do |theme|
  63.       theme.connect 'stylesheets/theme/:filename', :action => 'stylesheets'
  64.       theme.connect 'javascripts/theme/:filename', :action => 'javascript'
  65.       theme.connect 'images/theme/:filename',      :action => 'images'
  66.     end
  67.     # For the tests
  68.     get.connect 'theme/static_view_test', :controller => 'theme', :action => 'static_view_test'
  69.     map.connect 'plugins/filters/:filter/:public_action',
  70.       :controller => 'textfilter', :action => 'public_action'
  71.   end
  72.   map.connect 'previews/:id', :controller => 'articles', :action => 'preview'
  73.   # Work around the Bad URI bug
  74.   %w{ accounts backend files sidebar textfilter xml }.each do |i|
  75.     map.connect "#{i}", :controller => "#{i}", :action => 'index'
  76.     map.connect "#{i}/:action", :controller => "#{i}"
  77.     map.connect "#{i}/:action/:id", :controller => i, :id => nil
  78.   end
  79.   %w{advanced cache categories comments content profiles feedback general pages
  80.      resources sidebar textfilters themes trackbacks users settings tags }.each do |i|
  81.     map.connect "/admin/#{i}", :controller => "admin/#{i}", :action => 'index'
  82.     map.connect "/admin/#{i}/:action/:id", :controller => "admin/#{i}", :action => nil, :id => nil
  83.   end
  84.   map.connect '*from', :controller => 'articles', :action => 'redirect'
  85.   map.connect(':controller/:action/:id') do |default_route|
  86.     class << default_route
  87.       def recognize_with_deprecation(path, environment = {})
  88.         RAILS_DEFAULT_LOGGER.info "#{path} hit the default_route buffer"
  89.         recognize_without_deprecation(path, environment)
  90.       end
  91.       alias_method_chain :recognize, :deprecation
  92.       def generate_with_deprecation(options, hash, expire_on = {})
  93.         RAILS_DEFAULT_LOGGER.info "generate(#{options.inspect}, #{hash.inspect}, #{expire_on.inspect}) reached the default route"
  94.         #         if RAILS_ENV == 'test'
  95.         #           raise "Don't rely on default route generation"
  96.         #         end
  97.         generate_without_deprecation(options, hash, expire_on)
  98.       end
  99.       alias_method_chain :generate, :deprecation
  100.     end
  101.   end
  102. end