ruby 搜索功能-精准搜索-模糊搜索

实现搜索功能首先需要在controller 文件中增加 如下的语句,可以精准搜索和模糊搜索,具体看自己需要的情况

假设user项目中存在省份和城市这两列

那么,进行设置省份和城市的精准搜索

@user = @user.where('city  = ?', params[:city]) if params[:city].present?

@user = @user.where('province  =  ?', params[:province]) if params[:province].present?

同样的。也可以进行模糊搜索,假设存在invited_users 和 tel 这两列

那么进行模糊搜索
 

@user = @user.where('invited_users >= ? ' , "%#{params[:invited_users]}%") if params[:invited_users].present?

@user = @user.where('tel like ? ' , "%#{params[:tel]}%") if params[:tel].present?

然后进行页面的渲染,需要在index页面等等需要的页面进行引用

使用form表单

<%= form_tag '', method: :get do %>

    city: <%= text_field_tag :city, params[:city] %>

    province: <%= text_field_tag :province, params[:province] %>

    invited_users: <%= text_field_tag :invited_users, params[:invited_users] %>

    tel: <%= text_field_tag :tel, params[:tel] %>

    <%= submit_tag "查询", class: "form_submit", class: "btn btn-secondary" %>

<% end %>

链接的使用

一般使用的链接是用第二个,使用a标签会少一点,选择也不用input,是用select,设置样式等也是直接用select

所以第一段需要修改为form样式

 <a href="https://moonscan.io/tx/<%= claim.tx_id %>" > 查看tx </a> <br/>                                                      
    <%= link_to '查看tx', "https://moonscan.io/tx/#{claim.tx_id}"  %>  
<%= form.select :duration_strategy, options_for_select(["一年","三年"]), {}, {class: 'form-control'} %><br/> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值