将post索引页面设为根路径

时间:2016-07-15 12:40:59

标签: ruby-on-rails ruby-on-rails-4 routes

我想将post index页面设为根页面,并将/ posts重定向到根路径 索引的前缀是帖子...... 我在路线中尝试了这个(但我不知道它是否正确)

root "posts#index'
resources :posts, except: [:index]

所以现在我得到索引的根,但/ posts不工作...而不是得到错误,我希望它重定向到根页... 更改我的路线文件后,这是我的帖子路线...

 root GET    /                              posts#index
               posts POST   /posts(.:format)               posts#create
            new_post GET    /posts/new(.:format)           posts#new
           edit_post GET    /posts/:id/edit(.:format)      posts#edit
                post GET    /posts/:id(.:format)           posts#show
                     PATCH  /posts/:id(.:format)           posts#update
                     PUT    /posts/:id(.:format)           posts#update
                     DELETE /posts/:id(.:format)           posts#destroy

1 个答案:

答案 0 :(得分:1)

变化

root "posts#index"
resources :posts, except: [:index]

root "posts#index"
resources :posts