非常好用的模糊查询gem:ransack
2015-10-26 15:46
232 查看
https://github.com/activerecord-hackery/ransack
添加Gemfile
view中代码
<%= form_tag products_path, method: :get, class: "navbar-form navbar-left" do %>
<div class="form-group">
<%= search_field_tag("q[name_cont]", params["q"] && params["q"]["name_cont"],
class:"form-control input-sm search-form", placeholder: "输入商品名称")%>
</div>
<% end %>
controller里
def index
@q = Product.ransack(params[:q])
@products = @q.result(distinct: true)
end
其中 name_cont会对name字段进行模糊查询
添加Gemfile
gem 'ransack'
view中代码
<%= form_tag products_path, method: :get, class: "navbar-form navbar-left" do %>
<div class="form-group">
<%= search_field_tag("q[name_cont]", params["q"] && params["q"]["name_cont"],
class:"form-control input-sm search-form", placeholder: "输入商品名称")%>
</div>
<% end %>
controller里
def index
@q = Product.ransack(params[:q])
@products = @q.result(distinct: true)
end
其中 name_cont会对name字段进行模糊查询
相关文章推荐
- Plot the decision surfaces of ensembles of trees on the iris dataset
- new和malloc的区别
- JAVA Calendar的求一个月的最后一天多种方法实现
- PHP Mysql中文乱码问题
- Tomcat内存设置详解
- 非常好用的模糊查询gem:ransack
- UVALive-5713 Qin Shi Huang's National Road System (次小生成树)
- 移动端自动化测试开课了
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is yo
- 080.Function Pointer Arg 函数指针作为函数参数
- linux虚拟机与windows主机共享文件夹
- 7种形式的Android Dialog使用举例
- Python中list、tuple、dict区别
- logstash 收集tomcat log demo
- C#中弹出式窗体如何避免闪烁?
- 【Java】JavaEE性能问题的10大诱因
- ligerui ligerGrid 先填写搜索条件,在查询 因为如果数据比较多时,这样子比较消耗流量
- 网络开发---UIWebView
- MVC4.0 WebApi如何设置api支持namespace
- 老李分享:什么是好战略