From 4cd46e1b55c455ea94e70375eb2466ea931110a8 Mon Sep 17 00:00:00 2001 From: Galiant Date: Fri, 20 Apr 2018 18:22:18 +0000 Subject: [PATCH] Added search funcionality --- app/controllers/items_controller.rb | 5 ++++ app/views/items/search.html.erb | 44 ++++++++++++++++++++++++++++ app/views/layouts/_search.html.erb | 5 ++++ app/views/static_pages/home.html.erb | 16 +++++----- config/routes.rb | 6 ++-- 5 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 app/views/items/search.html.erb create mode 100644 app/views/layouts/_search.html.erb diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 49523d5..196811e 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -6,6 +6,11 @@ class ItemsController < ApplicationController def index @items = Item.all end + + def search + st = "%#{params[:q]}%" + @items = Item.where("title like ?", st) + end # GET /items/1 # GET /items/1.json diff --git a/app/views/items/search.html.erb b/app/views/items/search.html.erb new file mode 100644 index 0000000..295f9b1 --- /dev/null +++ b/app/views/items/search.html.erb @@ -0,0 +1,44 @@ +

<%= notice %>

+
+ +

Games

+ + <% @items.each do |item| %> +
+

<%= item.title %>

+ + <%= link_to (image_tag item.image_url, :class => "itemImage"), item %> + +

+ Console: <%= item.console %> +
+ Brand: <%= item.brand %> +
+ Genre: <%= item.genre %> +

+ +

<%= item.description %>

+ +

<%= item.price %>

+ +

+ Add to cart + <%= link_to 'Show', item, :class => "button", :role => "button" %> + + <% if user_signed_in? %> + <%= link_to 'Edit', edit_item_path(item), :class => "button", :role => "button" %> + <%= link_to 'Destroy', item, method: :delete, data: { confirm: 'Are you sure?' }, :class => "button", :role => "button" %> + <% end %> + + + +

+
+ <% end %> + + +
+ + + +
diff --git a/app/views/layouts/_search.html.erb b/app/views/layouts/_search.html.erb new file mode 100644 index 0000000..dfb9707 --- /dev/null +++ b/app/views/layouts/_search.html.erb @@ -0,0 +1,5 @@ +<%= form_tag("/search", :method => "post") do %> + <%= label_tag(:q, "Search For:") %> + <%= text_field_tag(:q) %> + <%= submit_tag("Search") %> +<% end %> \ No newline at end of file diff --git a/app/views/static_pages/home.html.erb b/app/views/static_pages/home.html.erb index edd371f..fda3ad7 100644 --- a/app/views/static_pages/home.html.erb +++ b/app/views/static_pages/home.html.erb @@ -1,15 +1,17 @@ <% provide(:title, 'Home') %>
- - - <%= render 'layouts/genres' %> - <%= render 'layouts/consoles' %> - - - <%= render 'layouts/iconscredit' %> + <%= render 'layouts/genres' %> + <%= render 'layouts/consoles' %> + + <%= render 'layouts/iconscredit' %>
+
+

Search

+ <%= render 'layouts/search' %> +
+ diff --git a/config/routes.rb b/config/routes.rb index 266979b..600c725 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,8 +22,10 @@ end -get '/checkout' , to: 'cart#createOrder' - get '/paid', to: 'static_pages#paid' + get '/checkout' , to: 'cart#createOrder' + get '/paid', to: 'static_pages#paid' + + post '/search', to: 'items#search' get 'cart/index'