ruby on rails 3-奇数路径生成



我目前正在处理管理面板中缺少的一些操作,其中之一就是编辑一个实体。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,但对于这个实体却不是。

编辑:从"rake routes"添加

               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"}

替换中的admin_cvs_path

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

带有

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

您可以通过在控制台中调用rake:routes来检查如何调用正确的路径助手

尝试更改:

= 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

这可能是因为单数和复数之间的冲突。例如:单数:人复数:人

为你的cvs_path提供单数,或者更好(在我看来)将你的cvs_path重命名为一条没有"复数"问题的路线。例如,repositories_path而不是cvs_path

相关内容

  • 没有找到相关文章

最新更新