Loop dentro de Loop en Rails Controller
Estoy intentando recuperar de mi base de datos todas las publicaciones y listarlas en orden DESC con respecto a su fecha de creación. Hasta ahora he logrado probar todas las publicaciones que pertenecen a una categoría, pero quiero mostrar todas las publicaciones sin importar a qué categoría pertenezcan. Sé que tengo que recorrer cada categoría y obtener las publicaciones de cada una, pero no sé cómo hacerlo. Aquí está mi código:
EDITAR:
def index
@institution = Institution.find(current_user.institution.id)
@categories = Category.all
@categories.each do |category|
@posts = Post.where("category_id = ? and institution_id = ?", category, @institution).order("created_at DESC")
end
authorize! :read, @post
respond_with(@posts)
end
¿Puede alguien indicarme el camino correcto?
EDIT 2: Mi vista (index.html.haml)
%h1 Listing posts
%table
%tr
%th Title
%th Description
%th User
%th Category
%th Type
%th Class
%th Institution
- @posts.each do |post|
%tr
%td= post.title
%td= post.description
%td= post.user_id
%td= post.category_id
%td= post.institution_id