Moved default page to "packages" controller.
Using a partial template to render search results. Show packages by default even without a query.
This commit is contained in:
parent
acd47f66d7
commit
f26f8a425b
5 changed files with 36 additions and 19 deletions
|
|
@ -1,7 +1,11 @@
|
|||
class PackagesController < ApplicationController
|
||||
def index
|
||||
query = '%'+params[:search]+'%'
|
||||
@packages = Package.where("description like ? or name like ?", query, query).order('name').first(20)
|
||||
if params[:search]
|
||||
query = '%'+params[:search]+'%'
|
||||
@packages = Package.where("description like ? or name like ?", query, query).order('name').first(20)
|
||||
else
|
||||
@packages = Package.order('name').first(20)
|
||||
end
|
||||
end
|
||||
|
||||
def with_screenshots
|
||||
|
|
|
|||
11
app/views/packages/_packages_search_results.html.erb
Normal file
11
app/views/packages/_packages_search_results.html.erb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<%# Show search results %>
|
||||
|
||||
<% if @packages %>
|
||||
<ul>
|
||||
<% @packages.each do |package| %>
|
||||
<li>
|
||||
<%= package.name %> <i>(<%= package.description %>)</i>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
<h1>Packages#index</h1>
|
||||
<p>Find me in app/views/packages/index.html.erb</p>
|
||||
<h1>Hello, Rails!</h1>
|
||||
|
||||
<ul>
|
||||
<% @packages.each do |package| %>
|
||||
<li>
|
||||
<%= package.name %> <i>(<%= package.description %>)</i>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<h1>Search for a package/description:</h1>
|
||||
|
||||
<%= form_tag(url_for, method: "get") do %>
|
||||
<%= text_field_tag :search, '', autofocus: true, placeholder: 'What are you looking for...' %>
|
||||
<%= submit_tag "Search" %>
|
||||
<% end %>
|
||||
|
||||
<h1>Search results</h1>
|
||||
|
||||
<%= render "packages_search_results", object: @packages %>
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
<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 %>
|
||||
<%= form_tag(url_for, method: "get") do %>
|
||||
<%= text_field_tag :search, '', autofocus: true, placeholder: 'Search criteria...' %>
|
||||
<%= submit_tag "Search" %>
|
||||
<% end %>
|
||||
|
||||
<h1>Search results</h1>
|
||||
|
||||
<%= @packages %>
|
||||
|
||||
<%= render "packages_search_results", object: @packages %>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ Debshots::Application.routes.draw do
|
|||
|
||||
# You can have the root of your site routed with "root"
|
||||
# root 'welcome#index'
|
||||
root to: "welcome#index"
|
||||
root to: "packages#index"
|
||||
|
||||
# Example of regular route:
|
||||
# get 'products/:id' => 'catalog#view'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue