gem 'ransack'

2019-08-05  本文已影响0人  biubiudog
gem 'ransack'

使用:

controller:

def index
  @q = Person.ransack(params[:q])
  @people = @q.result(distinct: true)
end

view

<%= search_form_for @q do |f| %>

  # Search if the name field contains...
  <%= f.label :name_cont %>
  <%= f.search_field :name_cont %>

  # Search if an associated articles.title starts with...
  <%= f.label :articles_title_start %>
  <%= f.search_field :articles_title_start %>

  <%= f.submit %>
<% end %>

界面中的排序

<%= sort_link(@q, :显示的字段, 描述, default_order: :desc) %>
上一篇 下一篇

猜你喜欢

热点阅读