A
A
Adil12013-12-06 14:31:54
Ruby on Rails
Adil1, 2013-12-06 14:31:54

How to properly render related objects in Rail 4?

Good day, I can’t understand how to make the correct render, there are posts, the posts have categories,
I registered in the view

<% Category.all.each do |category| %>
<li class="list-group-item"><%= link_to category.name, category_post_path(category_id:category.id) %> </li>
<% end %>

it is necessary that clicking on the link went to posts with the selected category, but does not render to the page with Posts#index,
but gives an error ActionController::UrlGenerationError in Posts#index
Showing c:/rails_projects/taskme/app/views/posts/index.html. erb where line #5 raised:
No route matches {:action=>"show", :controller=>"posts", :category_id=>1} missing required keys: [:id]
routes:
category_posts_path	 GET	 /categories/:category_id/posts(.:format)	 posts#index
POST	 /categories/:category_id/posts(.:format)	 posts#create
new_category_post_path	 GET	 /categories/:category_id/posts/new(.:format)	 posts#new
edit_category_post_path	 GET	 /categories/:category_id/posts/:id/edit(.:format)	 posts#edit

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor, 2013-12-06
@Adil1

M.b. is it about category_post S _path(category) ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question