0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

カテゴリー別一覧表示

Posted at

include~は表示順を降順にしてます。
search以降は検索機能のなのでなくていいです。

ideas.controller.rb
def index
    @idea2 = Idea.where({category_id: 2}).includes(:user).order("created_at DESC").search(params[:search])
    @idea3 = Idea.where({category_id: 3}).includes(:user).order("created_at DESC").search(params[:search])
    @idea4 = Idea.where({category_id: 4}).includes(:user).order("created_at DESC").search(params[:search])
    @idea5 = Idea.where({category_id: 5}).includes(:user).order("created_at DESC").search(params[:search])
end
index.html.rb
<div class="category bg-success"></div>
  <% @idea2.each do |idea| %>
  <%= link_to idea.title, idea_path(idea.id), class: :card__title%>
  <% end %>

  <div class="category bg-success">い</div>
  <% @idea3.each do |idea| %>
  <%= link_to idea.title, idea_path(idea.id), class: :card__title%>
  <% end %>

  <div class="category bg-success"></div>
  <% @idea4.each do |idea| %>
  <%= link_to idea.title, idea_path(idea.id), class: :card__title%>
  <% end %>

これでできました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?