Skip to content

Commit

Permalink
added searchkick
Browse files Browse the repository at this point in the history
  • Loading branch information
enterteg committed Mar 27, 2016
1 parent 880177a commit ec67fc5
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 7 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ gem 'dropzonejs-rails'
gem 'truncate_html', '~> 0.9.3'
gem 'lightbox2-rails'
gem 'will_paginate', '~> 3.0.6'
gem 'searchkick'
#------------------
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
Expand Down
17 changes: 17 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,23 @@ GEM
debug_inspector (0.0.2)
dropzonejs-rails (0.7.3)
rails (> 3.1)
elasticsearch (1.0.15)
elasticsearch-api (= 1.0.15)
elasticsearch-transport (= 1.0.15)
elasticsearch-api (1.0.15)
multi_json
elasticsearch-transport (1.0.15)
faraday
multi_json
erubis (2.7.0)
execjs (2.6.0)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
globalid (0.3.6)
activesupport (>= 4.1.0)
haml (4.0.7)
tilt
hashie (3.4.3)
i18n (0.7.0)
jbuilder (2.4.1)
activesupport (>= 3.0.0, < 5.1)
Expand All @@ -83,6 +94,7 @@ GEM
mini_portile2 (2.0.0)
minitest (5.8.4)
multi_json (1.11.2)
multipart-post (2.0.0)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
paperclip (4.3.6)
Expand Down Expand Up @@ -137,6 +149,10 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
searchkick (1.2.1)
activemodel
elasticsearch (>= 1)
hashie
spring (1.6.4)
sprockets (3.5.2)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -183,6 +199,7 @@ DEPENDENCIES
rails_12factor
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
searchkick
spring
tinymce-rails
truncate_html (~> 0.9.3)
Expand Down
5 changes: 4 additions & 1 deletion app/assets/stylesheets/posts.sass
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ section
text-align: center
padding: 10px 0px
font-size: 1.3rem
span
padding: 8px 15px
a
color: rgba(0,0,0,0.7)
text-decoration: none
Expand All @@ -147,7 +149,8 @@ section
&:hover
background-color: rgba(250,50,150,0.4)
.current
color: rgba(200,50,100,1)
text-shadow: 0px 0px 5px rgba(0,0,0,0.2)
color: rgba(250,250,250,0.7)
font-weight: bold
font-size: 1.5rem
font-style: normal
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def destroy_photo
end
end



private
def find_post
@post = Post.find(params[:id])
Expand Down
10 changes: 8 additions & 2 deletions app/controllers/public_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class PublicController < ApplicationController
end

def index
@posts = Post.where.not(id: 1).paginate(page: params[:page], per_page: 1)
@posts = Post.where.not(id: 1).paginate(page: params[:page], per_page: 4)
end

def travels
Expand All @@ -30,5 +30,11 @@ def about
@post = Post.find(1)
end


def search
if params[:search].present?
@posts = Post.search(params[:search])
else
redirect_to :index
end
end
end
3 changes: 2 additions & 1 deletion app/models/post.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class Post < ActiveRecord::Base
searchkick

validate :validate_travel_pin
belongs_to :category
has_many :photos, dependent: :destroy




default_scope { order(created_at: :desc) }

scope :travel, -> { where(category_id: 1).includes(:photos)}
Expand Down
4 changes: 4 additions & 0 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
|
= link_to '/about' do
%li= 'about me'
.search
= form_tag search_path, method: :get do
= text_field_tag :search
= submit_tag 'Search'
.right
-if current_user
.admin
Expand Down
5 changes: 2 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
post 'update_form' => 'posts#update_form'
delete 'destroy_photo/:id' => 'posts#destroy_photo', as: :destroy_photo


get '/search' => 'public#search', as: :search
post 'login' => 'session#create', as: :login
get 'logout' => 'session#destroy', as: :logout
get 'login' => 'session#new'
get 'stats' => 'admin#stats', as: :stats

resources :posts

resources :posts
get ':action' => 'public#action'

root 'public#index'
Expand Down

0 comments on commit ec67fc5

Please sign in to comment.