Have params in the link_to
method.
Describe what you want to pass as an argument to the path of the link_to
method.
ruby:index.html.erb
<ul class="gender-lists">
<li>
<%= link_to "ALL", root_path, class:"gender" %>
</li>
<li>
<%= link_to "MEN", search_posts_path(gender_id: 2), class:"gender" %>
</li>
<li>
<%= link_to "WOMEN", search_posts_path(gender_id: 3), class:"gender" %>
</li>
</ul>
If you write params [: gender_id]
, you can receive it with the controller.
posts_controller.rb
def search
@posts = Post.search(params[:gender_id])
end
Recommended Posts