我已经从请求中找到了这样的参数
params[:search] = {"user_id_in"=>[""], "status_in"=>[""], "priority_in"=>["", "8"]}
我需要清除它,因为元搜索宝石的工作原理不正确
params[:search] = {"priority_in"=>["8"]}
答案 0 :(得分:4)
我有一个双选用法的解决方案:
params[:search] = {"user_id_in"=>[""], "status_in"=>[""], "priority_in"=>["", "8"]} params[:search].select! do |k, v| v.select! do |vv| !vv.empty? end v.length > 0 end
答案 1 :(得分:2)
功能方法(当然,除了您要求进行就地更新之后的最后一次分配):
pairs = params[:search].map { |k, vs| [k, vs.reject(&:blank?)] }
params[:search] = Hash[pairs.select { |k, vs| vs.present? }]