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