0

我的管理区域有一个名为 'layout_admin' 的布局。在'layout_admin'中,我有:

<li><%= link_to 'Contenu', :action=>'index', :controller=>'contents' %></li>
<li><%= link_to 'Petitions', :controller => 'petitions', :action => 'index' %></li>

Contenu 的第一个链接工作正常,但第二个链接(用于请愿)让我遇到一个奇怪的错误:

路由错误没有路由匹配{:controller=>"admin/ edito "}

在地址栏中我有: localhost:3000/admin/petitions

在 routes.rb 我有:

namespace :admin do resources :petitions 
end

我还必须指出,“edito”是管理区域之外的另一个控制器,它有一个操作“索引”。在 routes.rb 我有get "edito/index"关于edito_controller。

有人知道问题的根源吗?谢谢。

全耙路线:

        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
4

1 回答 1

1

查看您的左栏中的路线名称rake routes?使用该信息来构建对不同路径助手的调用:

<li><%= link_to 'Contenu', admin_contents_path %></li>
<li><%= link_to 'Petitions', admin_petitions_path %></li>

一般来说,这就是您应该在 Rails 3+ 应用程序中构建 URL 的方式。

通读Rails Routing from the Outside In了解更多信息(特别是2.3:路径和 URL)。

更新:

您应该考虑_path在访问/admin/petitions.

我敢打赌,您在页面上有一个类似于此的链接:

<%= link_to "Link Text", :controller => "edito", :action => "index" %>

它试图editoadmin命名空间中查找,因为这是您访问时在应用程序中的位置/admin/petitions

要修复,您需要将其更新为如下所示:

<%= link_to "Link Text", edito_index_path %>

url_for对应用程序中的所有链接、表单和引用进行清洗、冲洗和重复操作。

于 2012-10-26T19:39:26.737 回答