From 266602ea1e97d886f031b80add7a760034221f76 Mon Sep 17 00:00:00 2001 From: tkimia Date: Tue, 22 Apr 2014 18:04:41 -0400 Subject: basic search complete --- app/controllers/search_controller.rb | 8 +++++--- app/views/search/go.html.erb | 25 +++++++++++++++++++++---- app/views/tournaments/index.html.erb | 4 ++++ 3 files changed, 30 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 9da649d..51aee9e 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -3,10 +3,12 @@ class SearchController < ApplicationController def go @query = params[:query] - if (@query.nil?) return; + if (@query.nil?) then + return + end - @tournaments = Tournament.where("name LIKE '#{@query}'") - @players = User.where("name LIKE '#{@query}") + @tournaments = Tournament.where("name LIKE '%#{@query}%'") + @players = User.where("name LIKE '%#{@query}%'") end diff --git a/app/views/search/go.html.erb b/app/views/search/go.html.erb index 12a76c8..6d5826f 100644 --- a/app/views/search/go.html.erb +++ b/app/views/search/go.html.erb @@ -1,6 +1,23 @@ -

Showing results for: <%= @query %>

+<%# Show search results if a query was not nill %> +<% if !@query.empty? %> +

Showing results for: <%= @query %>

+ <% if @tournaments.empty? and @players.empty? %> +

No results found for "<%= @query %>"

+ <% else %> + <% if @tournaments.length > 0 %> +

Tournaments

+ <% end %> + <% @tournaments.each do |t| %> + <%= render "common/show_tournament", :target => t %> + <% end %> -<% if @tounaments.empty? and @players.empty %> -

No results found for "<%= @query %>"

-<% else %> \ No newline at end of file + <% if @players.length > 0 %> +

Players

+ <% end %> + <% @players.each do |p| %> + <%= render "common/show_player", :target => p %> + <% end %> + + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb index 129f3de..06e1b25 100644 --- a/app/views/tournaments/index.html.erb +++ b/app/views/tournaments/index.html.erb @@ -2,16 +2,20 @@
<% if @tournaments.length > 0 %> + <%# Each tournament has a div for its listing %> <% @tournaments.each do |t| %> <%= render "common/show_tournament", :target => t %> <% end %> + <% else %> +

No tournaments going on right now... <% if current_user.can?(:create_tournament) %> Why not start your own? <% end %>

+ <% end %>
-- cgit v1.2.3-54-g00ecf