我的管理区域有一个名为'layout_admin'的布局。在'layout_admin'中,我有:
<li><%= link_to 'Contenu', :action=>'index', :controller=>'contents' %></li>
<li><%= link_to 'Petitions', :controller => 'petitions', :action => 'index' %></li>
Contenu的第一个链接工作正常,但第二个链接(用于请愿)让我犯了一个奇怪的错误:
路由错误 没有路线匹配{:controller =&gt;“admin / edito ”}
在地址栏中我有:localhost:3000 / admin / petitions
在routes.rb中我有:
namespace :admin do resources :petitions
end
我还必须确切地说“edito”是管理区域外的另一个控制器,它有一个动作“索引”。在routes.rb中,我有关于edito_controller的get "edito/index"
。
有人知道问题的根源吗? Thansk。
全耙路线:
temoignages GET /temoignages(.:format) temoignages#index
POST /temoignages(.:format) temoignages#create
new_temoignage GET /temoignages/new(.:format) temoignages#new
edit_temoignage GET /temoignages/:id/edit(.:format) temoignages#edit
temoignage GET /temoignages/:id(.:format) temoignages#show
PUT /temoignages/:id(.:format) temoignages#update
DELETE /temoignages/:id(.:format) temoignages#destroy
admin_petitions GET /admin/petitions(.:format) admin/petitions#index
POST /admin/petitions(.:format) admin/petitions#create
new_admin_petition GET /admin/petitions/new(.:format) admin/petitions#new
edit_admin_petition GET /admin/petitions/:id/edit(.:format) admin/petitions#edit
admin_petition GET /admin/petitions/:id(.:format) admin/petitions#show
PUT /admin/petitions/:id(.:format) admin/petitions#update
DELETE /admin/petitions/:id(.:format) admin/petitions#destroy
admin_contents GET /admin/contents(.:format) admin/contents#index
POST /admin/contents(.:format) admin/contents#create
new_admin_content GET /admin/contents/new(.:format) admin/contents#new
edit_admin_content GET /admin/contents/:id/edit(.:format) admin/contents#edit
admin_content GET /admin/contents/:id(.:format) admin/contents#show
PUT /admin/contents/:id(.:format) admin/contents#update
DELETE /admin/contents/:id(.:format) admin/contents#destroy
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
PUT /admin/posts/:id(.:format) admin/posts#update
DELETE /admin/posts/:id(.:format) admin/posts#destroy
GET /admin/posts(.:format) admin/posts#index
POST /admin/posts(.:format) admin/posts#create
GET /admin/posts/new(.:format) admin/posts#new
GET /admin/posts/:id/edit(.:format) admin/posts#edit
GET /admin/posts/:id(.:format) admin/posts#show
PUT /admin/posts/:id(.:format) admin/posts#update
DELETE /admin/posts/:id(.:format) admin/posts#destroy
admin_backend_index GET /admin/backend(.:format) admin/backend#index
POST /admin/backend(.:format) admin/backend#create
new_admin_backend GET /admin/backend/new(.:format) admin/backend#new
edit_admin_backend GET /admin/backend/:id/edit(.:format) admin/backend#edit
admin_backend GET /admin/backend/:id(.:format) admin/backend#show
PUT /admin/backend/:id(.:format) admin/backend#update
DELETE /admin/backend/:id(.:format) admin/backend#destroy
lois_index GET /lois/index(.:format) lois#index
lois_show GET /lois/show(.:format) lois#show
edito_index GET /edito/index(.:format) edito#index
reponses_index GET /reponses/index(.:format) reponses#index
reponses_show GET /reponses/show(.:format) reponses#show
lettres_index GET /lettres/index(.:format) lettres#index
lettres_show GET /lettres/show(.:format) lettres#show
accueils POST /accueils(.:format) accueils#create
new_accueils GET /accueils/new(.:format) accueils#new
edit_accueils GET /accueils/edit(.:format) accueils#edit
GET /accueils(.:format) accueils#show
PUT /accueils(.:format) accueils#update
DELETE /accueils(.:format) accueils#destroy
root / accueil#index
答案 0 :(得分:1)
查看rake routes
左栏中的路线名称?使用该信息构建对不同路径助手的调用:
<li><%= link_to 'Contenu', admin_contents_path %></li>
<li><%= link_to 'Petitions', admin_petitions_path %></li>
一般情况下,您应该如何在Rails 3+应用中构建网址。
阅读Rails Routing from the Outside In了解详情(尤其是2.3: Paths and URLs)。
<强>更新强>
您应该在访问_path
时提取的视图中使用这些/admin/petitions
风格的帮助器。
我打赌你在页面上有一个类似于此的链接:
<%= link_to "Link Text", :controller => "edito", :action => "index" %>
它正试图在edito
命名空间中找到admin
,因为当您访问/admin/petitions
时,这就是您在应用中的位置。
要修复,您需要将其更新为如下所示:
<%= link_to "Link Text", edito_index_path %>
对您应用中的所有链接,表单和url_for
引用进行清洗,冲洗和重复。