How to construct a clickable link with a scope using Ransack and Rails

元气小坏坏 提交于 2019-12-02 04:23:26

I was planning to do dirty way. (But haven't yet)

  • create search_form_for every scope (you will have 2 form for your case)
  • set hidden field with own criteria (as you do in your code but each in own form)
  • make submit button looks like link (with css I think it is not very difficult. You can see Bootstrap button appeared as link)

Not very clean or elegant.

I achieved this by creating hidden fields for each scope and then creating a button with onclick javascript:

<%= f.hidden_field :upward_trending %>

<%= button_tag(:type => 'submit', :class => 'btn btn-primary scope-button upward_trending', :id => "upward_trending", :onclick => "document.getElementById('q_downward_trending').value = 0; document.getElementById('q_upward_trending').value = 1;") do %>
    <i class="fa fa-chevron-up fa-2x"></i><br>Upward<br>Trending
    <% end %>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!