我添加了一個管理員命名,以我的應用程序時,那麼在登錄到管理區域時,它會是這樣:管理/網站和admin /頁/ 8路由錯誤添加管理員命名空間
所以這是我在我的路線.rb
namespace :admin do |admin|
match '/' => 'dashboard#index'
resources :websites
resources :pages
resources :sessions
get 'login' => 'sessions#new', :as => 'login'
get 'logout' => 'sessions#destroy', :as => 'logout'
end
我在app/controllers目錄中有admin_controller.rb。
class Admin::BaseController < ApplicationController
protect_from_forgery
include UrlHelper
...
我在app/controllers中創建了一個admin目錄。所以我這裏面的應用程序/控制器/管理/ websites_controller.rb
class Admin::WebsitesController < ApplicationController
建議類聯繫一些其他的答案:: WebsitesController <聯繫:: BaseController,但從來沒有爲我工作。如果我錯了,請告訴我。
因此,然後在我的佈局文件(app/views/layouts/application.html.erb)我有像這樣的鏈接edit_admin_website_path(@website)
給我路由錯誤Routing Error No route matches {:action=>"edit", :controller=>"admin/websites"}
Whyyyy ?! :(
這個錯誤返回的url選項通常應該是'{:action =>「edit」,:controller =>「admin/websites」,:id => 3}'或者任何id,你能檢查是否: '@ website'不是零,'@ website'被持久化(不是'new_record?') –
您使用的是哪個版本的Rails? –
一個巧妙的把戲:如果你發現'edit_admin_website_path(@website)'過於冗長,你可以使用(至少爲url /鏈接助手):'[:edit,:admin,@website]' –