search WIP

This commit is contained in:
Meutel 2015-08-03 13:14:56 +02:00
parent afa911284c
commit e47b68ff0e
2 changed files with 16 additions and 2 deletions

View File

@ -10,7 +10,13 @@ class BooksController < ApplicationController
end
def index
@books = Book.where(initial_filter).order(sort_col)
filters = initial_filter
if params[:s]
filters[0] << " AND sort like ?"
filters.push("%#{params[:s]}%")
end
puts filters
@books = Book.where(filters).order(sort_col)
.paginate(page: params[:page], per_page: session[:current_per_page])
@title = "Books"
respond_to do |format|

View File

@ -5,8 +5,16 @@
<% end %>
</div>
<div class="panel-body collapse" id="filterContent">
<%= yield(:latest_filter) %>
<%= render'layouts/initials' %>
<%= render'layouts/perpage' %>
<%= yield(:latest_filter) %>
<%= form_tag(method: :get, remote: true) do %>
<div class="input-group">
<span class="input-group-btn">
<%= button_tag "Seach", class: "btn btn-default" %>
</span>
<%= text_field_tag(:s, nil, placeholder: "Search for...", class: "form-control") %>
</div>
<% end %>
</div>
</div>