README.md in admino-0.0.15 vs README.md in admino-0.0.16

- old
+ new

@@ -117,13 +117,22 @@ ``` #### `filter_by` ```ruby +class Task < ActiveRecord::Base + enum :status, [:pending, :completed, :archived] + scope :title_matches, ->(text) { + where('title ILIKE ?', "%#{text}%") + } +end + class TasksQuery < Admino::Query::Base # ... filter_by :status, [:completed, :pending] + filter_by :deleted, [:with_deleted] + filter_by :status, Task.statuses.keys end ``` Just like a search field, with a declared filter group the `#scope` method will check the presence of a `params[:query][:status]` key. If it finds it (and its value corresponds to one of the declared scopes) it will augment the query with the scope itself: @@ -225,15 +234,28 @@ Admino offers some helpers that make it really easy to generate search forms and filtering links: ```erb <%# generate the search form %> <%= search_form_for(query) do |q| %> + <%# generate inputs from search_fields %> <p> <%= q.label :title_matches %> <%= q.text_field :title_matches %> </p> <p> <%= q.submit %> + </p> + + <%# generate inputs from filter_by %> + <p> + <%= q.label :status %> + <%= q.select :status, Task.statuses.keys %> + </p> + + <%# if filter_by has only one scope you can use a checkbox %> + <p> + <%= q.check_box :deleted, {}, checked_value: "with_deleted" %> + <%= q.label :deleted %> </p> <% end %> <%# generate the filtering links %> <% filters_for(query) do |filter_group| %>