Answer the question
In order to leave comments, you need to log in
How to correctly write a condition using params[params]?
At a dead end!
I can’t figure out how best to implement the task.
There are posts, posts have categories, categories have subcategories, they are in the Category table, but they have a parent_id when creating a post with a certain category, it is necessary to show the user a block with popular post names
. How best to implement this?
and how to use <% if params[:category_id] %>
can somehow alter the base?
Help me how to do it better to indicate a bunch of code on the view, I
tried to do something like this:@leftblock = Category.where(parent_id: 1)
<% if @leftblock.ids.to_s.include?(params[:category_id]) %>
Answer the question
In order to leave comments, you need to log in
In general, this logic needs to be pushed into the model.
If you have a category tree, I can recommend the awesome_nested_set gem . He organizes the work with the tree.
Show posts from the category in which a person creates a post?
Post.where(category_id: params[:category_id]) #или откуда вы там получаете id категории
<% if @category.id > 13 %>
<% Category.where(id:params[:category_id]).each do |c| %>
<% Category.where(parent_id:c.parent_id).each do |cc| %>
<ul>
<li>
<div class="pop_task_block">
<%=link_to cc.name, new_category_post_path(cc) %>
</div>
</li>
<% end %>
<% end %>
<% end %>
</ul>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question