My app is a web forum. Root page is a list of user-submitted categories. I click one and it links to a list of user-submitted posts about that category. I click a post and it links to a list of comments about that post. Those are the 3 tiers.
CATEGORIES INDEX This is a list of clickable categories
<% @categories.each do |category| %>
<%= link_to category.title, category %>
<% end %>
CATEGORIES SHOW I clicked a category, now I'm here looking at a list of posts
<%= render :partial => @category.posts %>
<% end %>
_POSTS The posts are rendered from this here partial
<%= div_for(post) do %>
<%= link_to post.body, Post %>
Clicking that post link takes me to POSTS INDEX.
I'm not sure if this is a desirable flow of a Rails app. It seems odd to go from Categories, to Posts, to Comments using Categories_Index, Categories_Show, and Posts_Index, respectively. I don't know how to display or submit comments from this POSTS INDEX. @comments.each do |comments| provides an error and so does the render: partial method. I can not use the same methods for Comments that I used for Categories and Posts.
MODELS Models are complete with has_many, belongs_to, etc.
CATEGORIES CONTROLLER def index @categories = Category.all end def create @category = current_user.categories.build(categories_params) end
POSTS CONTROLLER def create @category = Category.find(params[:category_id]) @post = @category.posts.new(post_params)
COMMENTS CONTROLLER def index @subcomments = Subcomment.all end def create @subcomment = current_user.subcomments.build(subcomment_params) end
ROUTES
Rails.application.routes.draw do
resources :comments
resources :posts
devise_for :users
resources :categories do
resources :posts do
end
resources :comments
end
root "categories#index"
I successfully added posts to categories. How can I add comments to posts? Is my approach correct?

