我正在使用 Ruby on Rails 3.2,我想知道是否有办法进行以下操作:
@categories.order('user_id = ? DESC', params[:id])
@categories.order('user_id = ? DESC', @user.id)
# Note: It is almost the same as `@categories.where('user_id = ?', params[:id])`
# but for the `order` clause.
上面的语句会产生这个错误:
ActiveRecord::StatementInvalid (Mysql2::Error: You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version for the
right syntax to use near '? DESC, ...