rails gem ransack 之模糊搜索

Posted 吕兴杰

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了rails gem ransack 之模糊搜索相关的知识,希望对你有一定的参考价值。

gem ‘ransack‘

PredicateDescriptionNotes
*_eq equal  
*_not_eq not equal  
*_matches matches with LIKE e.g. q[email_matches]=%@gmail.com
*_does_not_match does not match with LIKE  
*_matches_any Matches any  
*_matches_all Matches all  
*_does_not_match_any Does not match any  
*_does_not_match_all 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 is null  
*_not_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 Less than any SQL: col < value1 OR col < value2
*_lteq_any Less than or equal to any  
*_gt_any Greater than any  
*_gteq_any Greater than or equal to any  
*_matches_any *_does_not_match_any same as above but with LIKE
*_lt_all Less than all SQL: col < value1 AND col < value2
*_lteq_all Less than or equal to all  
*_gt_all Greater than all  
*_gteq_all Greater than or equal to all  
*_matches_all Matches all same as above but with LIKE
*_does_not_match_all Does not match all  
*_not_eq_all none of values in a set  
*_start Starts with SQL: col LIKE ‘value%‘
*_not_start Does not start with  
*_start_any Starts with any of  
*_start_all Starts with all of  
*_not_start_any Does not start with any of  
*_not_start_all Does not start with all of  
*_end Ends with SQL: col LIKE ‘%value‘
*_not_end Does not end with  
*_end_any Ends with any of  
*_end_all Ends with all of  
*_not_end_any    
*_not_end_all    
*_cont Contains value uses LIKE
*_cont_any Contains any of  
*_cont_all Contains all of  
*_not_cont Does not contain  
*_not_cont_any Does not contain any of  
*_not_cont_all Does not contain all of  
*_true is true  
*_false is false  

 

以上是关于rails gem ransack 之模糊搜索的主要内容,如果未能解决你的问题,请参考以下文章

Ransack,搜索多列,一个字段,rails 3

在 Ransack 上为 Rails 设置默认搜索参数

Rails,Ransack:如何在 HABTM 关系中搜索“所有”匹配项而不是“任何”匹配项

Ruby on Rails Ransack Datetime 到日期搜索

在rails应用程序中使用Ransack搜索表单中的关联多对多关联

Rails 3.1 Ransack HABTM