我正试图按created_at日期降序排序我的结果,但顺序。从句似乎不起作用。恐怕我已经盯着这个看太久了,如果有第二(或第三或更多)人来关注,我就会受益匪浅。
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])
应该@messages = @folder.messages.order("created_at DESC").where("deleted = ? or deleted IS NULL", false)
我有一个类似的问题,它看起来像created_at你要去属于文件夹而不是消息。
你能不能试试
@msgs = @folder.messages.order("messages.created_at DESC")