未定义方法`subject_type_path

问题描述 投票:0回答:1

我有一个从EntityType模型继承的SubjectType模型。我创建SubjectType的实例并将其保存在数据库中。它返回

INSERT INTO“ entity_types”(“ id”,“ value”,“ created_at”,“ updated_at”,“ type”)值(?,?,?,?,?)[[“ id”,2],[ “ value”,“ lola”],[“ created_at”,“ 2019-11-06 19:43:07.705355”],[“ updated_at”,“ 2019-11-06 19:43:07.705355”],[“ type “,” SubjectType“]]

但是当我尝试更新此EntityType时,出现此错误。

EntityTypes#edit中的NoMethodError

#### x1360ecd8的未定义方法`subject_type_path']

我的路线

Rails.application.routes.draw do
  resource :sessions
  resources :contacts
  resources :entity_types

 devise_for :users
 root to: 'entity_types#index'
 root to: 'contacts#new'


  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

铁路路线


Prefix Verb   URI Pattern                       Controller#Action
            new_sessions GET    /sessions/new(.:format)           sessions#new
           edit_sessions GET    /sessions/edit(.:format)          sessions#edit
                sessions GET    /sessions(.:format)               sessions#show
                         PATCH  /sessions(.:format)               sessions#update
                         PUT    /sessions(.:format)               sessions#update
                         DELETE /sessions(.:format)               sessions#destroy
                         POST   /sessions(.:format)               sessions#create
                     los GET    /los(.:format)                    los#index
                         POST   /los(.:format)                    los#create
                  new_lo GET    /los/new(.:format)                los#new
                 edit_lo GET    /los/:id/edit(.:format)           los#edit
                      lo GET    /los/:id(.:format)                los#show
                         PATCH  /los/:id(.:format)                los#update
                         PUT    /los/:id(.:format)                los#update
                         DELETE /los/:id(.:format)                los#destroy
                contacts GET    /contacts(.:format)               contacts#index
                         POST   /contacts(.:format)               contacts#create
             new_contact GET    /contacts/new(.:format)           contacts#new
            edit_contact GET    /contacts/:id/edit(.:format)      contacts#edit
                 contact GET    /contacts/:id(.:format)           contacts#show
                         PATCH  /contacts/:id(.:format)           contacts#update
                         PUT    /contacts/:id(.:format)           contacts#update
                         DELETE /contacts/:id(.:format)           contacts#destroy
            entity_types GET    /entity_types(.:format)           entity_types#index
                         POST   /entity_types(.:format)           entity_types#create
         new_entity_type GET    /entity_types/new(.:format)       entity_types#new
        edit_entity_type GET    /entity_types/:id/edit(.:format)  entity_types#edit
             entity_type GET    /entity_types/:id(.:format)       entity_types#show
                         PATCH  /entity_types/:id(.:format)       entity_types#update
                         PUT    /entity_types/:id(.:format)       entity_types#update
                         DELETE /entity_types/:id(.:format)       entity_types#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 GET    /users/sign_out(.:format)         devise/sessions#destroy
       new_user_password GET    /users/password/new(.:format)     devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)    devise/passwords#edit
           user_password PATCH  /users/password(.:format)         devise/passwords#update
                         PUT    /users/password(.:format)         devise/passwords#update
                         POST   /users/password(.:format)         devise/passwords#create
cancel_user_registration GET    /users/cancel(.:format)           devise/registrations#cancel
   new_user_registration GET    /users/sign_up(.:format)          devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)             devise/registrations#edit
       user_registration PATCH  /users(.:format)                  devise/registrations#update
                         PUT    /users(.:format)                  devise/registrations#update
                         DELETE /users(.:format)                  devise/registrations#destroy
                         POST   /users(.:format)                  devise/registrations#create
   new_user_confirmation GET    /users/confirmation/new(.:format) devise/confirmations#new
       user_confirmation GET    /users/confirmation(.:format)     devise/confirmations#show
                         POST   /users/confirmation(.:format)     devise/confirmations#create
                    root GET    /                                 entity_types#index
                         GET    /                                 entity_types#show
                         GET    /                                 los#index
                         GET    /

ruby-on-rails inheritance simple-form
1个回答
0
投票

正如@jvillian提到的,您尚未在subject_types文件中定义资源routes.rb

您需要将routes.rb更新为:

# routes.rb
Rails.application.routes.draw do
  resource :sessions
  resources :contacts
  resources :entity_types

  resources :subject_types # add this

  devise_for :users
  root to: 'entity_types#index'
  root to: 'contacts#new'


  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

我建议阅读每个routes.rb文件的指南:http://guides.rubyonrails.org/routing.html

© www.soinside.com 2019 - 2024. All rights reserved.