我添加了一个管理员命名,以我的应用程序时,那么在登录到管理区域时,它会是这样:管理/网站和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]' –