Search code examples
rubymongodbmongoidhamlpadrino

padrino 0.11.4 and mongoid 3.0.23 blog - posts not showing in front-end


After successfully following this tutorial, I tried creating a similar blog using mongoid as a stepping stone for a later project. Admin setup and model+controller creation went well, but posts don't show up in the front-end.

The admin is creating both users and posts and posts are being created with an associated user:

mongo shell

No error is thrown, nothing in browser console, the "posts" div is created, but it comes out empty.

Thanks for reading.

(edited)

UPDATE:

issue was in the ActiveRecord syntax used in posts controller. the following works with Mongoid:

PadrinoMongoid::App.controllers :posts do

  get :index do
    @posts = Post.order_by(:created_at.desc)
    render 'posts/index'
  end

  get :show, :with => :id do
    @post = Post.find(params[:id])
    render 'posts/show'
  end

end

Solution

  • Post.all(:order => 'created_at desc') is not a valid syntax to sort objects in Mongoid. Correct one would be Post.order_by(:created_at.asc).