diff options
| author | mo khan <mo@mokhan.ca> | 2014-10-19 17:05:41 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-10-19 17:05:41 -0600 |
| commit | c35586ca5319e8b1333d577cd5ced786d0c0c0a8 (patch) | |
| tree | 1a2b4265c51eb8d34f4081120e1ce29316d3284a | |
| parent | 976d92e081d8d6e4007dcb01a24d7407603dd018 (diff) | |
update tutorials pages to support site wide search.
| -rw-r--r-- | app/controllers/tutorials_controller.rb | 2 | ||||
| -rw-r--r-- | app/models/tutorial.rb | 1 | ||||
| -rw-r--r-- | app/views/tutorials/index.html.erb | 1 | ||||
| -rw-r--r-- | app/views/tutorials/show.html.erb | 1 |
4 files changed, 4 insertions, 1 deletions
diff --git a/app/controllers/tutorials_controller.rb b/app/controllers/tutorials_controller.rb index ff19d969..477c5327 100644 --- a/app/controllers/tutorials_controller.rb +++ b/app/controllers/tutorials_controller.rb @@ -1,6 +1,6 @@ class TutorialsController < ApplicationController def index - @tutorials = Tutorial.includes(:user).page(params[:page]).per(12) + @tutorials = Tutorial.includes(:user).search(params[:q]).page(page).per(per_page) end def show diff --git a/app/models/tutorial.rb b/app/models/tutorial.rb index d068d02b..dc89b526 100644 --- a/app/models/tutorial.rb +++ b/app/models/tutorial.rb @@ -3,6 +3,7 @@ class Tutorial < ActiveRecord::Base belongs_to :user acts_as_taggable default_scope -> { order('tutorials.created_at desc') } + scope :search, ->(query) { query.blank? ? all : where(["UPPER(heading) LIKE :query OR UPPER(description) LIKE :query", { query: "%#{query.upcase}%" }]) } def to_param "#{id}-#{heading.gsub(/[^a-z0-9]+/i, '-')}" diff --git a/app/views/tutorials/index.html.erb b/app/views/tutorials/index.html.erb index 38bc2766..198d8f41 100644 --- a/app/views/tutorials/index.html.erb +++ b/app/views/tutorials/index.html.erb @@ -1,3 +1,4 @@ +<%= provide(:search_path, tutorials_path) %> <div class="row-fluid"> <% @tutorials.each_slice(6).each do |batch| %> <ul class='thumbnails'> diff --git a/app/views/tutorials/show.html.erb b/app/views/tutorials/show.html.erb index c35f6f90..e9cd6e38 100644 --- a/app/views/tutorials/show.html.erb +++ b/app/views/tutorials/show.html.erb @@ -1,3 +1,4 @@ +<%= provide(:search_path, tutorials_path) %> <div class="row-fluid"> <div class="span12"> <div class="thumbnail"> |
