Ransack search for integer and string values from single search field

我是研究僧i 提交于 2019-12-24 04:26:14

问题


I am using Rails 4 with Ransack.

I cant make to work searching for integer and string values.

So far I tried this code.

In view:

<%= search_form_for @search do |f| %>
  <div class="field">
    <%= f.label :name_cont, "Nepieciešama meklēšāna pēc ID, vārda un telefona nr" %>         
    <%= f.text_field :name_or_phone_number_cont_or_id_eq, :placeholder => 'Meklēt pēc ID,vārda vai tel.nr.' %>
  </div>
<div class="actions"><%= f.submit "Search" %></div>
<% end %>

In controller :

 def index

    @search = Advertisement.search(params[:q])
    @advertisements = @search.result

   respond_with(@advertisements)
  end

This gives me error:

undefined method `name_or_phone_number_cont_or_id_eq' for

Is there any workaround to this problem? Or I need to convert id to string for search purposes ?

Thanks in advance.

来源:https://stackoverflow.com/questions/27148185/ransack-search-for-integer-and-string-values-from-single-search-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!