2011-05-27 130 views
0

我目前正在處理我的管理面板中的一些缺失操作,其中一個正在編輯實體。在routes.rb中文件包含以下條目:奇數路徑生成

namespace "admin" do 
    resources :users, :cvs, :settings, :languages, :vacancies, :countries, :languages, :companies 
    end 

我工作的edit.html.haml頁面上生成編輯實體的形式。此頁面HAML的代碼看起來如下:

= form_for @cv, :url => admin_cvs_path(@cv.id) do |form| 
    %table.clean 
    %tr 
     %th.border-left= 'Value' 
     %th.border-right= 'Key' 
    %tr 
     %td.border-left= 'Title' 
     %td.border-right= form.text_field :title 
    %tr 
     %td.border-left= 'First name' 
     %td.border-right= form.text_field :first_name 
    %tr 
     %td.border-left= 'Last name' 
     %td.border-right= form.text_field :last_name 
    %tr 
     %td.border-left= 'Gender' 
     %td.border-right= form.select :gender, options_for_select(['M', 'F', 'NA']) 
    %tr 
     %td.border-left= 'Address' 
     %td.border-right= form.text_field :address 
    %tr 
     %td.border-left= 'City' 
     %td.border-right= form.text_field :city 
    %tr 
     %td.border-left= 'Postal code' 
     %td.border-right= form.text_field :postal_code 
    %tr 
     %td.border-left= 'Country' 
     %td.border-right= form.select :country_id, options_from_collection_for_select(@countries, :id, :name) 
    %tr 
     %td.border-left.border-right{:colspan => 2}= form.submit 'update' 

然而,看着生成的HTML我收到以下輸出時:

<form id="edit_cv_2" class="edit_cv" method="post" action="/admin/cvs.2" accept-charset="UTF-8"> 

,如果我沒有記錯的目標行爲是錯誤的。它應該是/admin/cvs/2而不是生成的/admin/cvs.2。 奇怪的是,另一個實體的完全相同的代碼會生成正確的html,但不適用於此。

編輯:從添加了 '耙路線'

   root  /(.:format)       {:action=>"index", :controller=>"static"} 
      select_cv GET /select(.:format)     {:action=>"select", :controller=>"static"} 
     categorize_cv POST /categorize(.:format)    {:action=>"categorize", :controller=>"static"} 
      match_cv POST /match(.:format)     {:action=>"match", :controller=>"static"} 
      semantic POST /semantic(.:format)     {:action=>"semantic", :controller=>"static"} 
      cv_show GET /cvs/show/:id(.:format)    {:action=>"show", :controller=>"cvs"} 
      esco_new GET /cvs/new(.:format)     {:action=>"new",:controller=>"cvs"} 
      esco_view GET /cvs/esco_view/:id(.:format)  {:action=>"esco_view", :controller=>"cvs"} 
     esco_match POST /cvs/esco_match/:id(.:format)  {:action=>"esco_match", :controller=>"cvs"} 
     new_session GET /session/new(.:format)    {:action=>"new", :controller=>"session"} 
    create_session PUT /session/create(.:format)   {:action=>"create", :controller=>"session"} 
    destroy_session DELETE /session/destroy(.:format)   {:action=>"destroy", :controller=>"session"} 
     admin_users GET /admin/users(.:format)    {:action=>"index", :controller=>"admin/users"} 
        POST /admin/users(.:format)    {:action=>"create", :controller=>"admin/users"} 
    new_admin_user GET /admin/users/new(.:format)   {:action=>"new", :controller=>"admin/users"} 
    edit_admin_user GET /admin/users/:id/edit(.:format)  {:action=>"edit", :controller=>"admin/users"} 
     admin_user GET /admin/users/:id(.:format)   {:action=>"show", :controller=>"admin/users"} 
        PUT /admin/users/:id(.:format)   {:action=>"update", :controller=>"admin/users"} 
        DELETE /admin/users/:id(.:format)   {:action=>"destroy", :controller=>"admin/users"} 
    admin_settings GET /admin/settings(.:format)   {:action=>"index", :controller=>"admin/settings"} 
        POST /admin/settings(.:format)   {:action=>"create", :controller=>"admin/settings"} 
    new_admin_setting GET /admin/settings/new(.:format)  {:action=>"new", :controller=>"admin/settings"} 
edit_admin_setting GET /admin/settings/:id/edit(.:format) {:action=>"edit", :controller=>"admin/settings"} 
     admin_setting GET /admin/settings/:id(.:format)  {:action=>"show", :controller=>"admin/settings"} 
        PUT /admin/settings/:id(.:format)  {:action=>"update", :controller=>"admin/settings"} 
        DELETE /admin/settings/:id(.:format)  {:action=>"destroy", :controller=>"admin/settings"} 
    admin_languages GET /admin/languages(.:format)   {:action=>"index", :controller=>"admin/languages"} 
        POST /admin/languages(.:format)   {:action=>"create", :controller=>"admin/languages"} 
new_admin_language GET /admin/languages/new(.:format)  {:action=>"new", :controller=>"admin/languages"} 
edit_admin_language GET /admin/languages/:id/edit(.:format) {:action=>"edit", :controller=>"admin/languages"} 
    admin_language GET /admin/languages/:id(.:format)  {:action=>"show", :controller=>"admin/languages"} 
        PUT /admin/languages/:id(.:format)  {:action=>"update", :controller=>"admin/languages"} 
        DELETE /admin/languages/:id(.:format)  {:action=>"destroy", :controller=>"admin/languages"} 
    admin_vacancies GET /admin/vacancies(.:format)   {:action=>"index", :controller=>"admin/vacancies"} 
        POST /admin/vacancies(.:format)   {:action=>"create", :controller=>"admin/vacancies"} 
    new_admin_vacancy GET /admin/vacancies/new(.:format)  {:action=>"new",:controller=>"admin/vacancies"} 
edit_admin_vacancy GET /admin/vacancies/:id/edit(.:format) {:action=>"edit", :controller=>"admin/vacancies"} 
     admin_vacancy GET /admin/vacancies/:id(.:format)  {:action=>"show", :controller=>"admin/vacancies"} 
        PUT /admin/vacancies/:id(.:format)  {:action=>"update", :controller=>"admin/vacancies"} 
        DELETE /admin/vacancies/:id(.:format)  {:action=>"destroy", :controller=>"admin/vacancies"} 
    admin_countries GET /admin/countries(.:format)   {:action=>"index", :controller=>"admin/countries"} 
        POST /admin/countries(.:format)   {:action=>"create", :controller=>"admin/countries"} 
    new_admin_country GET /admin/countries/new(.:format)  {:action=>"new",:controller=>"admin/countries"} 
edit_admin_country GET /admin/countries/:id/edit(.:format) {:action=>"edit", :controller=>"admin/countries"} 
     admin_country GET /admin/countries/:id(.:format)  {:action=>"show", :controller=>"admin/countries"} 
        PUT /admin/countries/:id(.:format)  {:action=>"update", :controller=>"admin/countries"} 
        DELETE /admin/countries/:id(.:format)  {:action=>"destroy", :controller=>"admin/countries"} 
        GET /admin/languages(.:format)   {:action=>"index", :controller=>"admin/languages"} 
        POST /admin/languages(.:format)   {:action=>"create", :controller=>"admin/languages"} 
        GET /admin/languages/new(.:format)  {:action=>"new",:controller=>"admin/languages"} 
        GET /admin/languages/:id/edit(.:format) {:action=>"edit", :controller=>"admin/languages"} 
        GET /admin/languages/:id(.:format)  {:action=>"show", :controller=>"admin/languages"} 
        PUT /admin/languages/:id(.:format)  {:action=>"update", :controller=>"admin/languages"} 
        DELETE /admin/languages/:id(.:format)  {:action=>"destroy", :controller=>"admin/languages"} 
    admin_companies GET /admin/companies(.:format)   {:action=>"index", :controller=>"admin/companies"} 
        POST /admin/companies(.:format)   {:action=>"create", :controller=>"admin/companies"} 
    new_admin_company GET /admin/companies/new(.:format)  {:action=>"new",:controller=>"admin/companies"} 
edit_admin_company GET /admin/companies/:id/edit(.:format) {:action=>"edit", :controller=>"admin/companies"} 
     admin_company GET /admin/companies/:id(.:format)  {:action=>"show", :controller=>"admin/companies"} 
        PUT /admin/companies/:id(.:format)  {:action=>"update", :controller=>"admin/companies"} 
        DELETE /admin/companies/:id(.:format)  {:action=>"destroy", :controller=>"admin/companies"} 
      admin_cvs GET /admin/cvs(.:format)    {:action=>"index", :controller=>"admin/cvs"} 
        POST /admin/cvs(.:format)    {:action=>"create", :controller=>"admin/cvs"} 
     new_admin_cv GET /admin/cvs/new(.:format)   {:action=>"new",:controller=>"admin/cvs"} 
     edit_admin_cv GET /admin/cvs/:id/edit(.:format)  {:action=>"edit", :controller=>"admin/cvs"} 
      admin_cv GET /admin/cvs/:id(.:format)   {:action=>"show", :controller=>"admin/cvs"} 
        PUT /admin/cvs/:id(.:format)   {:action=>"update", :controller=>"admin/cvs"} 
        DELETE /admin/cvs/:id(.:format)   {:action=>"destroy", :controller=>"admin/cvs"} 
admin_static_index GET /admin/static(.:format)    {:action=>"index", :controller=>"admin/static"} 
        POST /admin/static(.:format)    {:action=>"create", :controller=>"admin/static"} 
    new_admin_static GET /admin/static/new(.:format)   {:action=>"new",:controller=>"admin/static"} 
    edit_admin_static GET /admin/static/:id/edit(.:format) {:action=>"edit", :controller=>"admin/static"} 
     admin_static GET /admin/static/:id(.:format)   {:action=>"show", :controller=>"admin/static"} 
        PUT /admin/static/:id(.:format)   {:action=>"update", :controller=>"admin/static"} 
        DELETE /admin/static/:id(.:format)   {:action=>"destroy", :controller=>"admin/static"} 
     admin_save_cv POST /admin/cvs/save(.:format)   {:action=>"save", :controller=>"admin/cvs"} 
     admin_index GET /admin(.:format)     {:action=>"index", :controller=>"admin/static"} 

回答

2

= form_for @cv, :url => admin_cvs_path(@cv.id) do |form| 

更換admin_cvs_path與

= form_for @cv, :url => admin_cv_path(@cv.id) do |form| 

您可以檢查如何通過調用耙調用正確的路徑助手:航線控制檯

+0

謝謝這解決了這個問題....感覺很傻,因爲注意到一個... – 2011-05-27 12:28:32

0

嘗試改變:

= form_for @cv, :url => admin_cvs_path(@cv.id) do |form| 

要:

= form_for @cv, :url => admin_cvs_path(@cv) do |form| 

如果沒有幫助,請發佈內容:

rake routes | grep cv 
+0

添加了耙子輸出 – 2011-05-27 12:27:48

0

這是因爲可能單數和複數之間的衝突。 例如: 奇異:人 Plurar:人

供應奇異您cvs_path或更好的(在我看來)重新命名您的cvs_path的路線沒有「多」的問題。例如一個repositories_path,而不是一個cvs_path