现在是需要多字段模糊查询,我现在是大概这样做的
def searchUser
search = params[:search]
offset = params[:offset]
rows = params[:limit]
users = User.where("user_id like ? or user_name like ? or password like ? or gender like ? or
device_name like ? or os_name like ? or os_version like ? or device_id like ? or user_type like ?",
"%#{search}%","%#{search}%","%#{search}%","%#{search}%",
"%#{search}%","%#{search}%","%#{search}%","%#{search}%","%#{search}%")
.offset(offset)
.limit(rows)
result = {:total => User.count, :rows => users}
render json: result
end
上面的写法很有种原生 sql 的赶脚 想问下,有没有类似下面这样的写法?查询手册里面关于条件查询就一句话带过了
User.where("xxx" like ?,"%#{search}%") or where("xxx" like ?,"%#{search}%")