Odd path generation
I'm currently working on some of the missing actions in my administration panel, and one of these is editing an entity. The routes.rb files contains the following entries:
namespace "admin" do
resources :users, :cvs, :settings, :languages, :vacancies, :countries, :languages, :companies
end
I'm working on the edit.html.haml page to generate a form for editing the entity. The code of this haml page looks as following:
= 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'
However, when looking at the generated HTML I receive the following output:
<form id="edit_cv_2" class="edit_cv" method="post" action="/admin/cvs.2" accept-charset="UTF-8">
if I recall correctly the target action is wrong. It should be /admin/cvs/2 instead of the generated /admin/cvs.2. The odd thing is, the exact same code for another entity generates the correct html, but not for this one.
edit: adding out from '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开发者_JAVA百科(.: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"}
Replace admin_cvs_path in
= form_for @cv, :url => admin_cvs_path(@cv.id) do |form|
with
= form_for @cv, :url => admin_cv_path(@cv.id) do |form|
You can check how to call proper path helpers by calling rake:routes in console
Try changing:
= form_for @cv, :url => admin_cvs_path(@cv.id) do |form|
To:
= form_for @cv, :url => admin_cvs_path(@cv) do |form|
If that doesn't help, please post the contents of:
rake routes | grep cv
This is probably because of a conflict between singular and plural. For example: Singular: person Plurar: persons
Supply the singular for your cvs_path or better (in my opinion) rename your cvs_path to a route without the 'plural' problem. For example a repositories_path instead of a cvs_path
精彩评论