zoukankan      html  css  js  c++  java
  • ransack gem rails

    ransack主要用于搜索

    用法

    <div class="form-input-hr">
    <%= text_field_tag("query[name_cont]", params["query"] && params["query"]["name_cont"]) %>
    </div>


    products = Product.ransack(params[:query])
    @sort = params[:sort].blank? ? 'id' : params[:sort]
    @order = params[:order].blank? ? 'desc' : params[:order]
    if @order == 'desc'
    @next_order = 'asc'
    else
    @next_order = 'desc'
    end
    @products = paginate(products.result.includes(:shop).order("#{@sort} #{@order}"))

    *_eq - equal
    *_not_eq - not equal
    *_matches - matches with LIKE, e.g. q[email_matches]=%@gmail.com
    Also: *_does_not_match, *_matches_any, *_matches_all, *_does_not_match_any, *_does_not_match_all
    *_lt - less than
    *_lteq - less than or equal
    *_gt - greater than
    *_gteq - greater than or equal
    *_present - not null and not empty, e.g. q[name_present]=1 (SQL: col is not null AND col != '')
    *_blank - is null or empty. (SQL: col is null OR col = '')
    *_null, *_not_null - is null, is not null
    *_in - match any values in array, e.g. q[name_in][]=Alice&q[name_in][]=Bob
    *_not_in - match none of values in array
    *_lt_any, *_lteq_any, *_gt_any, *_gteq_any - Compare to list of values, at least positive. (SQL: col > value1 OR col > value2)
    *_matches_any, *_does_not_match_any - same as above but with LIKE
    *_lt_all, *_lteq_all, *_gt_all, *_gteq_all - Compare to list of values, all positive. (SQL: col > value1 AND col > value2)
    *_matches_all, *_does_not_match_all - same as above but with LIKE
    *_not_eq_all - none of values in a set
    *_start, *_not_start, *_start_any, *_start_all, *_not_start_any, *_not_start_all - start with, (SQL: col LIKE 'value%')
    *_end, *_not_end, *_end_any, *_end_all, *_not_end_any, *_not_end_all - end with, (SQL: col LIKE '%value')
    *_cont, *_cont_any, *_cont_all, *_not_cont, *_not_cont_any, *_not_cont_all - contains value, using LIKE
    *_true, *_false - is true and is false
    ————————————————
    版权声明:本文为CSDN博主「tang05709」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/tang05709/java/article/details/79507620

  • 相关阅读:
    JAVA NIO之文件通道
    Java NIO之缓冲区
    LinkedList 源码分析(JDK 1.8)
    ArrayList 源码详细分析
    自己动手实现一个简单的JSON解析器
    科普:String hashCode 方法为什么选择数字31作为乘子
    LinkedHashMap 源码详细分析(JDK1.8)
    HashMap 源码详细分析(JDK1.8)
    python创建目录
    python3 内置方法 字符串转换为字典
  • 原文地址:https://www.cnblogs.com/qinyan20/p/12886057.html
Copyright © 2011-2022 走看看