Fulltext search for packages works

This commit is contained in:
Christoph Haas 2013-07-27 01:48:01 +02:00
parent 8df03296e9
commit acd47f66d7
3 changed files with 17 additions and 3 deletions

View file

@ -1,6 +1,7 @@
class PackagesController < ApplicationController class PackagesController < ApplicationController
def index def index
@packages = Package.order('name').first(20) query = '%'+params[:search]+'%'
@packages = Package.where("description like ? or name like ?", query, query).order('name').first(20)
end end
def with_screenshots def with_screenshots

View file

@ -1 +1,14 @@
<h1>Hello, Rails!</h1> <h1>Hello, Rails!</h1>
<h1>Search for a package/description:</h1>
<form action="/packages" method="get">
<div>
<input id="search" name="search" type="text" />
</div>
</form>
<%= form_tag("/packages", method: "get") do %>
<%= text_field_tag :search, '', autofocus: true, placeholder: 'Search criteria...' %>
<%= submit_tag "Search" %>
<% end %>