diff --git a/Gemfile b/Gemfile index 672b5418..486e554b 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,7 @@ gem 'devise', '~> 4.4', '>= 4.4.3' gem 'pundit', '~> 1.1' gem 'rolify', '~> 5.2' gem 'sucker_punch', '~> 2.0', '>= 2.0.4' +gem 'pg_search', '~> 2.1', '>= 2.1.2' gem 'figaro', '~> 1.1', '>= 1.1.1' gem 'gravatar_image_tag', '~> 1.2' gem 'inline_svg', '~> 1.3', '>= 1.3.1' diff --git a/Gemfile.lock b/Gemfile.lock index 6ceef81d..23fa96ee 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -346,6 +346,10 @@ GEM parser (2.5.1.0) ast (~> 2.4.0) pg (0.21.0) + pg_search (2.1.2) + activerecord (>= 4.2) + activesupport (>= 4.2) + arel (>= 6) popper_js (1.12.9) powerpack (0.1.1) pry (0.11.3) @@ -529,6 +533,7 @@ DEPENDENCIES mini_magick (= 4.7.0) minitest-reporters (= 1.1.14) pg (~> 0.18) + pg_search (~> 2.1, >= 2.1.2) pry-byebug (~> 3.6) pry-rails (~> 0.3.6) puma (~> 3.7) diff --git a/app/assets/stylesheets/custom.scss b/app/assets/stylesheets/custom.scss index f183a0ad..7d40ad30 100644 --- a/app/assets/stylesheets/custom.scss +++ b/app/assets/stylesheets/custom.scss @@ -201,42 +201,12 @@ body { background-color: lighten($dark-indigo, 5); } -.search-form { - flex-direction: column; - align-items: flex-end; +.container-search-bar { + padding: 0; - @include media-breakpoint-up(md) { - flex-direction: row; - align-items: center; - } -} - -.search-group { - display: flex; - align-items: baseline; - margin-right: 0; - margin-bottom: .5rem !important; - - @include media-breakpoint-up(md) { - margin-right: .5rem; - margin-bottom: 0 !important; - } -} - -.search-label { - margin-right: .5rem; -} - -.search-input { - width: initial; -} - -.btn-search { - width: 100%; - margin: 0; - - @include media-breakpoint-up(md) { - width: initial; + @include media-breakpoint-up(sm) { + padding-left: 15px; + padding-right: 15px; } } diff --git a/app/controllers/searches_controller.rb b/app/controllers/searches_controller.rb index 764eb425..22400eab 100644 --- a/app/controllers/searches_controller.rb +++ b/app/controllers/searches_controller.rb @@ -2,7 +2,8 @@ class SearchesController < ApplicationController require "will_paginate/array" def show - @groups = Group.search(params[:location], params[:group]) + @groups = Group.unhidden + .search(params[:keywords]) .paginate(page: params[:page], per_page: 15) end end diff --git a/app/models/group.rb b/app/models/group.rb index 940c06b1..ab3b19f9 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -1,5 +1,8 @@ class Group < ApplicationRecord + include PgSearch + resourcify + after_create :add_owner_as_organizer after_update :update_members_role @@ -22,10 +25,7 @@ class Group < ApplicationRecord validates :description, presence: true, length: { minimum: 70 } validates :image, presence: true - scope :search, -> (location, group_name) { - where("lower(location) LIKE :location AND lower(name) LIKE :name", - location: "%#{location.downcase}%", name: "%#{group_name.downcase}%") - } + pg_search_scope :search, against: [:name, :location, :description] scope :unhidden, -> { where(hidden: false, sample_group: false) diff --git a/app/views/groups/_groups.html.erb b/app/views/groups/_groups.html.erb new file mode 100644 index 00000000..a497f91e --- /dev/null +++ b/app/views/groups/_groups.html.erb @@ -0,0 +1,24 @@ +
+
+
+ +
+

+ <%= yield :groups_header_title %> +

+
+ +
+ <%= render groups %> +
+ + + +
+
+
diff --git a/app/views/groups/index.html.erb b/app/views/groups/index.html.erb index f7db3f68..36ca194e 100644 --- a/app/views/groups/index.html.erb +++ b/app/views/groups/index.html.erb @@ -1,19 +1,7 @@ <%= render "searches/search_bar" %> -
-
-
-

Unhidden Groups

+<% content_for :groups_header_title do %> + Unhidden Groups +<% end %> -
- <%= render @groups %> -
-
-
- <%= will_paginate @groups, - :renderer => WillPaginate::ActionView::Bootstrap4LinkRenderer %> -
-
-
-
-
+<%= render "groups", groups: @groups %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 3c1e653e..515bf067 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,7 +8,6 @@ <%= render "header" %> - <%= render "searches/search_bar" if home_page? %> <%= render "flash_messages" %>
diff --git a/app/views/searches/_search_bar.html.erb b/app/views/searches/_search_bar.html.erb index d3388780..b9da03af 100644 --- a/app/views/searches/_search_bar.html.erb +++ b/app/views/searches/_search_bar.html.erb @@ -1,24 +1,26 @@