我正在尝试按 created_at 日期以降序对结果进行排序,但 order.clause 似乎不起作用。恐怕我已经看这个太久了,完全可以从第二组(或第三组或更多)眼睛中受益。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)
关于ruby-on-rails - Ruby On Rails 3 问题排序查询结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5782816/