summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/tutorials_controller.rb2
-rw-r--r--app/models/tutorial.rb1
-rw-r--r--app/views/tutorials/index.html.erb1
-rw-r--r--app/views/tutorials/show.html.erb1
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">