6. 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 %>
# Attributes may be chained. Search multiple attributes for one value...
<%= f.label :name_or_description_or_email_or_articles_title_cont %>
<%= f.search_field :name_or_description_or_email_or_articles_title_cont %>
<%= f.submit %>
<% end %>
6
7. Pros
• easy to introduce
• realizes complex conditions with Advanced Mode
• searches by associations
• used by many people(, and easy to find references)
7
8. Cons
• includes many hack codes for ActiveRecord
• difficult to maintenance
• CI failed on 5-2-stable
!
• I do not like the design about Authorization
8
12. in controller
def index
search_params = Pickel.permit(params, :name, :age_gt, :posts_title_start)
@search = Pickel.search(User, search_params)
@users = @search.result
end
12
13. in view
<%= form_for @search do |f| %>
<%# Search records contains the value %>
<%= f.label :name_cont %>
<%= f.search_field :name_cont %>
<%# Search records grater than the value %>
<%= f.label :age_gt %>
<%= f.number_field :age_gt %>
<%# Search records an associated posts.title starts with the value %>
<%= f.label :posts_title_start %>
<%= f.search_field :posts_title_start %>
<%= f.submit %>
<% end %>
13
14. Concept (Difference from Ransack)
• refrains hack for ActiveRecord
• basically builds a SQL in ActiveRecord.merge
• (However, Arel is used)
• allows search conditions by the StrongParameter
• uses form_for as it is
14