rails改变根路由

时间:2012-07-10 05:22:58

标签: ruby-on-rails

我正在使用Enki gem创建一个博客应用程序。默认情况下,它将根路径发送到posts_controller.rb的索引

root :to => 'posts#index'

但是,我不希望博客成为根页面,因此,我使用homes_controller.rb创建了一个脚手架并尝试将其设置为根

root :to => 'homes#index'

然而,尽管做了这样的改变,但是当我启动服务器时,它仍然会解决帖子#index。即使我尝试使用新浏览器(即它不是缓存问题),它也会这样做。

我已经复制了下面的config / routes.rb文件。任何人都可以解释......

Enki::Application.routes.draw do


  namespace :admin do
    resource :session

    resources :posts, :pages do
      post 'preview', :on => :collection
    end
    resources :comments
    resources :undo_items do
      post 'undo', :on => :member
    end

    match 'health(/:action)' => 'health', :action => 'index', :as => :health

    root :to => 'dashboard#show'
  end

  resources :archives, :only => [:index]
  resources :pages, :only => [:show]
resources :homes
  constraints :year => /\d{4}/, :month => /\d{2}/, :day => /\d{2}/ do
    get ':year/:month/:day/:slug/comments'  => 'comments#index'
    post ':year/:month/:day/:slug/comments' => 'comments#create'
    get ':year/:month/:day/:slug/comments/new' => 'comments#new'
    get ':year/:month/:day/:slug' => 'posts#show'
  end

  scope :to => 'posts#index' do
    get 'posts.:format', :as => :formatted_posts
    get '(:tag)', :as => :posts
  end

  #root :to => 'posts#index'
  root :to => 'homes#index'

end

1 个答案:

答案 0 :(得分:0)

将根放在routes文件的顶部。 Rails路由从上到下解析