Query "where" whit ruby on rails

I’ve in my app, posts as ideas, and these ideas belongs to an activity and a status.
And I want to sort them by activity for one status so I did in my controller

@idees_en_place = Idee.where(statut_id= "2")
@activites = Activite.all

And in my view :

<% @activites.each do |activite| %>
  <div class="idee en-place col-lg-5" style="background:#<%= activite.color%>">
    <h2><%= activite.name %></h2>
    <p>
     <% @idees_en_place.where(activite_id = activite.id).limit(3).each do |idee| %>
     <div class="idee">
       <h6><%= link_to idee.title, idee %></h6>
      </div>
     <% end %>
  </p>
  </div>
<% end %>

But that doesn’t work, in each part of an activity the ideas are not sorted.
I think it’s a little mistake but I don’t know how to resolve this


Source: ruby

Leave a Reply