3

例如,在我的 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
4

1 回答 1

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
于 2012-12-26T04:38:28.617 回答