5
我是一个rails新手(构建我的第一个应用程序),现在我的routes.rb是相当混乱。我想知道组织/格式化所有内容的最佳方式是什么,以便很容易看出发生了什么并避免愚蠢的路由错误。Rails:如何格式化和组织路线
任何一般的提示或简化的例子,将不胜感激。
的routes.rb
Rails.application.routes.draw do
resources :posts
get 'users/index'
#devise_for :admins
namespace :super_admin do #superadmin stuff
resources :dashboard, only: [:index]
end
devise_for :super_admins, path: "super_admin", controllers: { registrations: "registrations", sessions: "super_admin/sessions" } #lets super admin sign in
get 'welcome/index'
root to: "welcome#index"
match '/teachers', to: 'teachers#index', via: 'get'
#route to delete users
match 'users/:id' => 'users#destroy', :via => :delete, :as => :admin_destroy_user
match '/users/:id', to: 'users#show', via: 'get'
#routes for registration
devise_for :users, controllers: { registrations: "registrations" }
devise_for :teachers, controllers: { registrations: "teacher/registrations" }
get 'users/:id/posts' => 'users#posts', :as => :user_posts
match '/users', to: 'users#index', via: 'get'
match '/about', to: 'about#index', via: 'get'
match '/teachers/:id', to: 'teachers#show', via: 'get'
match '/teachers/list', to: 'teachers#list', via: 'get'
get 'super_admin/dashboard/new_user', :as => :super_admin_new_user
resources :users, :only =>[:show]
除了您重复欢迎索引路线两次之外,它对我来说看起来不错。如果你想让它成为你的根路由,只需使用'root'welcome#index''并删除它上面的get请求。 – Cyzanfar
我会建议问这个问题是StackOverflow聊天,如果你有足够的代表。此外,我建议删除过多的间距。我在代码段之间使用不超过1个空格。 – onebree