I started writing an app which reviews books, articles etc(model name: Piece ) and has the option to review chapters or smaller sections (Sections, Subsections, and Subsubsections models)
I want to be able to generate a general overview of the Piece where all of the nested Sections, Subsections, and Subsubsections and their attributes will be listed in one view. So my routes.rb file looks like this:
resources :pieces do
resources :sections do
resources :subsections do
resources :subsubsections
end
end
end
Which I have since learned is sloppy but its too late for me now. For now, I have been able to do this from the subsubsections, because it has acces to all the parent parameters (piece_id, section_id, etc). But this means that I have to jump down the tree into the Subsubsection view and then go from there, whereas I would like to be able to access all these parameters from the Piece controller so that I can link straight from the Piece view to the more general overview, without having to go all the way down the chain.
I apologize if this is a simple question, I only started recently.
My models like like this:
class Subsubsection < ActiveRecord::Base
belongs_to :subsection
end
class Subsection < ActiveRecord::Base
belongs_to :section
has_many :subsubsections
end
class Section < ActiveRecord::Base
belongs_to :piece
has_many :subsections
end
class Piece < ActiveRecord::Base
has_many :sections
has_many :links
end
And the way i am accessing the general overview for now is using the index action of the subsubsections controller:
def index
@piece = Piece.find(params[:piece_id])
@section = @piece.sections.find(params[:section_id])
@subsection = @section.subsections.find(params[:subsection_id])
end
My view accesses it like this:
<p><%= link_to "'General Piece Overview", piece_section_subsection_subsubsections_path(@piece, @section, @subsection), class: 'section_name' %></p>
Heres the link to the project in case it helps: