mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-17 05:15:36 +00:00
Added tournament search
This commit is contained in:
@@ -80,7 +80,11 @@ class TournamentsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@tournaments = Tournament.all.sort_by{|t| t.daysUntil}
|
if params[:search]
|
||||||
|
@tournaments = Tournament.search(params[:search]).order("created_at DESC")
|
||||||
|
else
|
||||||
|
@tournaments = Tournament.all.sort_by{|t| t.daysUntil}.first(20)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ class Tournament < ActiveRecord::Base
|
|||||||
|
|
||||||
validates :date, :name, :tournament_type, :address, :director, :director_email , presence: true
|
validates :date, :name, :tournament_type, :address, :director, :director_email , presence: true
|
||||||
|
|
||||||
|
def self.search(search)
|
||||||
|
where("date LIKE ? or name LIKE ?", "%#{search}%", "%#{search}%")
|
||||||
|
end
|
||||||
|
|
||||||
def daysUntil
|
def daysUntil
|
||||||
time = (Date.today - self.date).to_i
|
time = (Date.today - self.date).to_i
|
||||||
if time < 0
|
if time < 0
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
<li><%= link_to "About", "/static_pages/about" %></li>
|
<li><%= link_to "About", "/static_pages/about" %></li>
|
||||||
<% if user_signed_in? %>
|
<% if user_signed_in? %>
|
||||||
<li><%=link_to "Log out", destroy_user_session_url ,:method => 'delete' %></li>
|
<li><%=link_to "Log out", destroy_user_session_url ,:method => 'delete' %></li>
|
||||||
<li><%=link_to "Edit user", edit_user_registration_path %></li>
|
<li><%=link_to "Edit user", edit_user_registration_path %></li>
|
||||||
<li><%=link_to "My tournaments","/static_pages/my_tournaments" %></li>
|
<li><%=link_to "My tournaments","/static_pages/my_tournaments" %></li>
|
||||||
<% else %>
|
<% else %>
|
||||||
<li><%= link_to "Log In" , new_user_session_path %></li>
|
<li><%= link_to "Log In" , new_user_session_path %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
<h1>Pick A Tournament</h1>
|
<h1>Upcoming Tournaments</h1> <%= form_tag(tournaments_path, :method => "get", id: "search-form") do %>
|
||||||
|
<%= text_field_tag :search, params[:search], placeholder: "Search Tournaments" %>
|
||||||
|
<%= submit_tag "Search" %>
|
||||||
|
<% end %>
|
||||||
|
<p>Search by name or date YYYY-MM-DD</p>
|
||||||
<script>
|
<script>
|
||||||
// $(document).ready(function() {
|
// $(document).ready(function() {
|
||||||
// $('#tournamentList').dataTable();
|
// $('#tournamentList').dataTable();
|
||||||
|
|||||||
Reference in New Issue
Block a user