I'm trying to order my results in descending order by created_at date, but the order.clause doesn't seem to be working. I'm afraid I've been looking at this for entirely too long and could totally benefit from a second (or third or more) set of eyes.
mailbox_controller.rb
:
def show
current_user = User.find(session[:user_id])
@folder = Folder.where("user_id = #{current_user.id}").first
@msgs = @folder.messages.order("created_at DESC")
@messages = @msgs.where(["deleted IS NULL"] || ["deleted = ?", false]).paginate :per_page => 5, :page => params[:page]
end
@msgs = @folder.messages.order("created_at DESC")
@messages = @msgs.where(["deleted IS NULL"] || ["deleted = ?", false])
should be
@messages = @folder.messages.order("created_at DESC").where("deleted = ? or deleted IS NULL", false)
I had a similar problem and it looks like the created_at you're going for belongs to Folder instead of messages.
Can you try with
@msgs = @folder.messages.order("messages.created_at DESC")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.