0

私が書いている本のレビューアプリで多相関係を作成しました。私のアプリケーションは、ネストされたモデルを持っています:ピース>>セクション>>サブセクション>>サブセクションで、KeyConceptと呼ばれるこれらのすべてに属するモデルを作成しました。私はこれらのそれぞれがキーコンセプトを持つことができると考えています。Controller#indexのLoadError

keyconceptsコントローラのインデックスアクションを表示しようとすると、私が理解できないエラーが発生しています。 名前の競合が原因である可能性がありますが、私はそれを理解するのに十分な経験がありません。

私はこのようなルックスを取得していますエラー:

Unable to autoload constant KeyConceptsController, expected /home/david/Documents/Learning/StuddyBuddy/app/controllers/key_concepts_controller.rb to define it 

    else 
     require_or_load(expanded, qualified_name) 
     raise LoadError, "Unable to autoload constant #{qualified_name}, expected #{file_path} to define it" unless from_mod.const_defined?(const_name, false) 
     return from_mod.const_get(const_name) 
    end 
    elsif mod = autoload_module!(from_mod, const_name, qualified_name, path_suffix) 

マイkeyconceptsコントローラは次のようになります。

key_concepts_controller.rb クラスKey_conceptsController < ApplicationControllerに はKeyconceptsHelper

def whereami 
    if params[:piece_id] 
     @piece = Piece.find(params[:piece_id]) 
     @keyconcept = @piece.key_concepts.find(params[:id]) 

     here = @piece 
     parameter = :piece_id 
     type = "Piece" 
    elsif params[:section_id] 
     @section = Section.find(params[:section_id]) 
     @piece = @section.piece_id 
     @keyconcept = @section.key_concepts.find(params[:id]) 

     here = @section 
     parameter = :section_id 
     type = "Section" 
    elsif params[:subsection_id] 
     @subsection = Subsection.find(params[:subsection_id]) 
     @section = @subsection.section_id 
     @piece = Section.find([email protected]).piece_id 

     here = @subsection 
     parameter = :subsection_id 
     type = "Subsection" 
    elsif params[:subsubsection_id] 
     @subsubsection = Subsubsection.find(params[:subsubsection_id]) 
     @subsection = @subsubsection.subsection_id 
     @section = Subsection.find([email protected]).section_id 
     @piece = Section.find([email protected]).piece_id 

     here = @subsubsection 
     parameter = :subsubsection_id 
     type = "Subsubsection" 
    end 
end 

def redirect 
    if type == "Piece" 
     @redirect = redirect_to piece_path(@piece) 
    elsif type == "Section" 
     @redirect = redirect_to piece_section_path(@piece, @section) 
    elsif type == "Subsection" 
     @redirect = redirect_to piece_section_subsection_path(@piece, @section, @subsection) 
    elsif type == "Subsubsection" 
     @redirect = redirect_to piece_section_subsection_subsubsection_path(@piece, @section, @subsection, @subsubsection) 
    end 
end 

def index 
    whereami.call 
    @piece = Piece.find(params[:piece_id]) 
    @keyconcept = @piece.key_concepts.find(params[:id]) 
    @redirect = redirect.call 
end 

def show 
    whereami.call 
    redirect.call 
end 

def new 
    @keyconcept = KeyConcept.new 
    @keyconcept.conceptable_id = here.id 
end 

def create 
    whereami.call 

    @keyconcept = KeyConcept.new(keyconcept_params) 

    @keyconcept.conceptable_id = params[parameter] 
    @keyconcept.conceptable_type = type 
    @keyconcept.save 

    redirect.call 
end 

def destroy 
    here.destroy 
    redirect.call 
    flash.notice = "#{type} '#{here.name}' from '#{@piece.name}' deleted!" 
end 

def edit 
    whereami.call 
end 

def update 
    whereami.call 

    here.update(keyconcept_params) 
    flash.notice = "#{type} '#{here.name}' Updated!" 
    redirect.call 
end 


end 

含まリンクは、親パイのショーアクションから来ますここでCEモデル:

<% @piece.key_concepts.each do |concept| %> 
<li> 
    <%= link_to concept.definition, [@piece, @keyconcept] %> 
    <!-- we didn't use #piece_key_concept_path(@piece, @keyconcept), class: 'section_name' and it worked --> 
</li> 

どのように私は道によるkeyconcepts「ショー」アクションにリンクしていますか?

resources :pieces do 
    resources :sections do 
    resources :subsections do 
     resources :subsubsections 
    end 
    end 
    resources :links 
end 

resources :pieces, :sections, :subsections, :subsubsections do 
    resources :connections, only: [:index, :new, :edit, :update, :destroy, :create] 
    resources :keyconcepts, only: [:index, :new, :edit, :update, :destroy, :create, :show] 
end 

key_concept.rb

class KeyConcept < ActiveRecord::Base 
    belongs_to :conceptable, polymorphic: true 
end 

piece.rb

:だからroutes.rbをファイルには、次のようになります/

:私はそう私はちょうどindexアクションにリンクすることができましたhavent

class Piece < ActiveRecord::Base 
    include Connectable 
    include Conceptable 
    has_many :sections 
    has_many :subsections, through: :sections 
    has_many :links 
end 

(モデル/関心事/ conceptable.rb) モジュール概念的 はactivesupportのを拡張::懸念

included do 
    has_many :keyconcepts, as: :conceptable 
    end 
end 
+0

ためthisを参照してください。 –

答えて

0

まあ問題は命名された規則

あなたkey_concepts_controllerクラス名も

KeyConceptsController < ApplicationController 

モデル場合は、適切な規則

に従うことを確認しなければなりません名前はKeyConceptです。ファイル名はkey_concept.rb

である必要があります。

コントローラ名は同じルート

resources : key_concepts 

で行くkey_concepts_controller.rb

でなければなりませんKeyConceptsControllerとファイル名でなければなりませんあなたはきっとレールに新しいようで詳細

関連する問題