I am wondering how to access routes in nested resources in rails. I added categories and it as broken my application.
Routes:
resources :categories do
resources :posts do
resources :comments
end
end
It errors out in this:
<% @posts.each_with_index do |post, index| %>
<%= link_to post do %> # originally, this used to work but now it says 'undefined method "post_path"'
<li class="post-title"><%= truncate post.title, length: 50 %></li>
<li class="post-content"><%= truncate post.content, length: 400 %></li>
<li><span class="post-comments"><%= post.comments.count %> comments</span></li>
<% end %>
My root is set to posts#index and has a listing of posts. However, the route nesting (originally I didn't have categories) has broken the routes.
Running rake routes I get in part this:
category_posts GET /categories/:category_id/posts(.:format) posts#index
POST /categories/:category_id/posts(.:format) posts#create
new_category_post GET /categories/:category_id/posts/new(.:format) posts#new
edit_category_post GET /categories/:category_id/posts/:id/edit(.:format) posts#edit
category_post GET /categories/:category_id/posts/:id(.:format) posts#show
PATCH /categories/:category_id/posts/:id(.:format) posts#update
PUT /categories/:category_id/posts/:id(.:format) posts#update
DELETE /categories/:category_id/posts/:id(.:format) posts#destroy
How can I adjust routes to compensate for nesting? Or is there a better way to nest?