在我的rails应用程序中,我举例说明了注册操作(http:// * :3000 / users / sign_up)并收到错误:
No route matches {:controller=>"devise/vehicle_types", :action=>"search_vehicle_type"}
我认为这是因为我在路由的设计名称空间...但我怎么能正常呈现注册视图?我的布局部分看起来如此:
= render :partial => 'vehicle_types/findtype'
和这部分:
.form
= form_tag :controller => 'vehicle_types', :action => 'search_vehicle_type' do
= select("post", "MFA_ID", Manufacturer.all.collect {|p| [ p.MFA_BRAND, p.MFA_ID ] }, {:prompt => 'Марка'}, :class => "login-input man-select")
= select_tag "models", options_for_select(['Модель', nil]), :class => "login-input mod-select", :prompt => 'Модель', :disabled => :true
= select_tag "fueltype", options_for_select([['Тип топлива', nil], ['Не важно', nil], ['Бензин', 53302], ['Дизель', 53205], ['Газ', 53241], ['Гибрид', 55554], ['Электродвигатель', 52433]]), :class => "login-input fuel-select"
= text_field_tag "year", nil, :placeholder => "Год выпуска", :class => "login-input"
.submit-area
.left
= submit_tag "Выбор", :class => "orange-button"
在其他页面上(非设计)一切正常,但是当我进行密码恢复或注册时,我会得到错误。但为什么?以及如何解决?
也是路线的一部分:
Oleg::Application.routes.draw do
devise_for :users
match '/search_vehicle_type' => 'vehicle_types#search_vehicle_type'
root :to => 'pages#index'
end
此外,我在这里阅读了https://github.com/plataformatec/devise/issues/471的链接,但是如何部分做?
和rake routes | grep devise
new_admin_session GET /admins/sign_in(.:format) devise/sessions#new
admin_session POST /admins/sign_in(.:format) devise/sessions#create
destroy_admin_session DELETE /admins/sign_out(.:format) devise/sessions#destroy
admin_password POST /admins/password(.:format) devise/passwords#create
new_admin_password GET /admins/password/new(.:format) devise/passwords#new
edit_admin_password GET /admins/password/edit(.:format) devise/passwords#edit
PUT /admins/password(.:format) devise/passwords#update
cancel_admin_registration GET /admins/cancel(.:format) devise/registrations#cancel
admin_registration POST /admins(.:format) devise/registrations#create
new_admin_registration GET /admins/sign_up(.:format) devise/registrations#new
edit_admin_registration GET /admins/edit(.:format) devise/registrations#edit
PUT /admins(.:format) devise/registrations#update
DELETE /admins(.:format) devise/registrations#destroy
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
答案 0 :(得分:0)
虽然它可能不是最好的样式,但最简单的解决方法是在form_tag中使用实际路径:
.form
= form_tag "/search_vehicle_type" do
# Rest of the form
另一种方法是在routes.rb文件中命名路由:
match '/search_vehicle_type' => 'vehicle_types#search_vehicle_type', :as => :search_vehicle_type
然后在form_tag中使用该命名路由:
.form
= form_tag search_vehicle_type_path do
# Rest of the form