my routes.rb
get '/admin/login' => 'admin/sessions#new'
get '/admin/logout' => 'admin/sessions#destroy'
get '/admin' => 'admin/dashboard#index'
get 'blog' => 'blogs#index'
get ':id' => 'posts#show'
get 'posts/:id' => redirect('%{id}')
get 'blog/:id' => 'blogs#show'
get 'category/:id' => 'posts#index'
namespace :admin do
resources :sessions, only: [:new, :create, :destroy]
resources :login, only: [:index, :edit]
resources :categories
resources :admins, only: [:index, :edit, :update, :new, :create, :destroy]
resources :dashboard, only:[:index]
resources :settings, only:[:new, :create, :edit, :update]
resources :posts
resources :blogs
end
resources :home, only:[:index]
resources :posts, only:[:index, :show]
resources :blogs, only:[:index, :show]
当我尝试进入/ admin / login页面时,它似乎是帖子页面或其他东西。但我可以看到登录表单。只是它不是管理页面(我的意思是没有我的管理员css或者它在我的正常前端帖子页面中似乎是管理员登录表单。当我尝试使用我的用户名和密码登录时,它给出了这个错误:
ActionView::MissingTemplate in Admin::Posts#new
然后我从routes.rb中删除这部分
get 'blog' => 'blogs#index'
get ':id' => 'posts#show'
get 'posts/:id' => redirect('%{id}')
get 'blog/:id' => 'blogs#show'
get 'category/:id' => 'posts#index'
然后我可以进入管理页面。然后我再次粘贴这部分仍然可以使用管理面板没有错误,我不明白。
有人可以帮忙吗? (对不起我的英文)这是rake路线
Prefix Verb URI Pattern Controller#Action
root GET / home#index
admin_login GET /admin/login(.:format) admin/sessions#new
admin_logout GET /admin/logout(.:format) admin/sessions#destroy
admin GET /admin(.:format) admin/dashboard#index
blog GET /blog(.:format) blogs#index
GET /:id(.:format) posts#show
GET /posts/:id(.:format) redirect(301, %{id})
GET /blog/:id(.:format) blogs#show
GET /category/:id(.:format) posts#index
admin_sessions POST /admin/sessions(.:format) admin/sessions#create
new_admin_session GET /admin/sessions/new(.:format) admin/sessions#new
admin_session DELETE /admin/sessions/:id(.:format) admin/sessions#destroy
admin_login_index GET /admin/login(.:format) admin/login#index
edit_admin_login GET /admin/login/:id/edit(.:format) admin/login#edit
admin_categories GET /admin/categories(.:format) admin/categories#index
POST /admin/categories(.:format) admin/categories#create
new_admin_category GET /admin/categories/new(.:format) admin/categories#new
edit_admin_category GET /admin/categories/:id/edit(.:format) admin/categories#edit
admin_category GET /admin/categories/:id(.:format) admin/categories#show
PATCH /admin/categories/:id(.:format) admin/categories#update
PUT /admin/categories/:id(.:format) admin/categories#update
DELETE /admin/categories/:id(.:format) admin/categories#destroy
admin_admins GET /admin/admins(.:format) admin/admins#index
POST /admin/admins(.:format) admin/admins#create
new_admin_admin GET /admin/admins/new(.:format) admin/admins#new
edit_admin_admin GET /admin/admins/:id/edit(.:format) admin/admins#edit
admin_admin PATCH /admin/admins/:id(.:format) admin/admins#update
PUT /admin/admins/:id(.:format) admin/admins#update
DELETE /admin/admins/:id(.:format) admin/admins#destroy
admin_dashboard_index GET /admin/dashboard(.:format) admin/dashboard#index
admin_settings POST /admin/settings(.:format) admin/settings#create
new_admin_setting GET /admin/settings/new(.:format) admin/settings#new
edit_admin_setting GET /admin/settings/:id/edit(.:format) admin/settings#edit
admin_setting PATCH /admin/settings/:id(.:format) admin/settings#update
PUT /admin/settings/:id(.:format) admin/settings#update
admin_posts GET /admin/posts(.:format) admin/posts#index
POST /admin/posts(.:format) admin/posts#create
new_admin_post GET /admin/posts/new(.:format) admin/posts#new
edit_admin_post GET /admin/posts/:id/edit(.:format) admin/posts#edit
admin_post GET /admin/posts/:id(.:format) admin/posts#show
PATCH /admin/posts/:id(.:format) admin/posts#update
PUT /admin/posts/:id(.:format) admin/posts#update
DELETE /admin/posts/:id(.:format) admin/posts#destroy
admin_blogs GET /admin/blogs(.:format) admin/blogs#index
POST /admin/blogs(.:format) admin/blogs#create
new_admin_blog GET /admin/blogs/new(.:format) admin/blogs#new
edit_admin_blog GET /admin/blogs/:id/edit(.:format) admin/blogs#edit
admin_blog GET /admin/blogs/:id(.:format) admin/blogs#show
PATCH /admin/blogs/:id(.:format) admin/blogs#update
PUT /admin/blogs/:id(.:format) admin/blogs#update
DELETE /admin/blogs/:id(.:format) admin/blogs#destroy
home_index GET /home(.:format) home#index
posts GET /posts(.:format) posts#index
post GET /posts/:id(.:format) posts#show
blogs GET /blogs(.:format) blogs#index
GET /blogs/:id(.:format) blogs#show
答案 0 :(得分:0)
似乎问题就在这两行上。
get ':id' => 'posts#show'
get 'posts/:id' => redirect('%{id}')
试试这个
get 'posts/:id' => 'posts#show'