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
|
class PackagesController < ApplicationController
|
||||||
def index
|
def index
|
||||||
query = '%'+params[:search]+'%'
|
if params[:search]
|
||||||
@packages = Package.where("description like ? or name like ?", query, query).order('name').first(20)
|
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
|
end
|
||||||
|
|
||||||
def with_screenshots
|
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>
|
<h1>Hello, Rails!</h1>
|
||||||
<p>Find me in app/views/packages/index.html.erb</p>
|
|
||||||
|
|
||||||
<ul>
|
<h1>Search for a package/description:</h1>
|
||||||
<% @packages.each do |package| %>
|
|
||||||
<li>
|
<%= form_tag(url_for, method: "get") do %>
|
||||||
<%= package.name %> <i>(<%= package.description %>)</i>
|
<%= text_field_tag :search, '', autofocus: true, placeholder: 'What are you looking for...' %>
|
||||||
</li>
|
<%= submit_tag "Search" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
|
||||||
|
<h1>Search results</h1>
|
||||||
|
|
||||||
|
<%= render "packages_search_results", object: @packages %>
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
<h1>Hello, Rails!</h1>
|
<h1>Hello, Rails!</h1>
|
||||||
|
|
||||||
<h1>Search for a package/description:</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(url_for, method: "get") do %>
|
||||||
<%= form_tag("/packages", method: "get") do %>
|
|
||||||
<%= text_field_tag :search, '', autofocus: true, placeholder: 'Search criteria...' %>
|
<%= text_field_tag :search, '', autofocus: true, placeholder: 'Search criteria...' %>
|
||||||
<%= submit_tag "Search" %>
|
<%= submit_tag "Search" %>
|
||||||
<% end %>
|
<% 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"
|
# You can have the root of your site routed with "root"
|
||||||
# root 'welcome#index'
|
# root 'welcome#index'
|
||||||
root to: "welcome#index"
|
root to: "packages#index"
|
||||||
|
|
||||||
# Example of regular route:
|
# Example of regular route:
|
||||||
# get 'products/:id' => 'catalog#view'
|
# get 'products/:id' => 'catalog#view'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue