Commit 083a28fd by tady

search page

parent 935b356a
...@@ -306,7 +306,7 @@ GEM ...@@ -306,7 +306,7 @@ GEM
slim (2.0.2) slim (2.0.2)
temple (~> 0.6.6) temple (~> 0.6.6)
tilt (>= 1.3.3, < 2.1) tilt (>= 1.3.3, < 2.1)
slop (3.4.7) slop (3.5.0)
sprockets (2.11.0) sprockets (2.11.0)
hike (~> 1.2) hike (~> 1.2)
multi_json (~> 1.0) multi_json (~> 1.0)
......
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
...@@ -17,3 +17,11 @@ ...@@ -17,3 +17,11 @@
.text-shadow { .text-shadow {
color: #999999; color: #999999;
} }
a .text-link {
color: #1e0fbe;
}
a:visited .text-link {
color: #609;
}
// Place all the styles related to the search controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class SearchController < ApplicationController
before_action :require_login
def show
if params[:q].present?
scope = Post.search(params[:q])
else
scope = Post.order(updated_at: :desc)
end
@count = scope.count
@posts = scope.limit(10).decorate
end
end
class PostsDecorator < Draper::CollectionDecorator class PostsDecorator < Draper::CollectionDecorator
def related_tags
_tags = self.map do |_post|
_post.tags
end.flatten.uniq
TagDecorator.decorate_collection(_tags)
end
def related_authors
_authors = self.map do |_post|
_post.author
end.flatten.uniq
UserDecorator.decorate_collection(_authors)
end
end end
class SearchDecorator < Draper::Decorator
delegate_all
# Define presentation-specific methods here. Helpers are accessed through
# `helpers` (aka `h`). You can override attributes, for example:
#
# def created_at
# helpers.content_tag :span, class: 'time' do
# object.created_at.strftime("%a %m/%d/%y")
# end
# end
end
class UserDecorator < Draper::Decorator
delegate_all
end
module SearchHelper
end
...@@ -4,7 +4,7 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation" ...@@ -4,7 +4,7 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation"
a.navbar-brand href=root_path Rendezvous a.navbar-brand href=root_path Rendezvous
.collapse.navbar-collapse .collapse.navbar-collapse
form#app-search-form.navbar-form.navbar-left action=posts_path role="search" form#app-search-form.navbar-form.navbar-left action=search_path role="search"
.input-group .input-group
input.form-control name="q" placeholder="Search" type="text" value=params[:q] / input.form-control name="q" placeholder="Search" type="text" value=params[:q] /
span.input-group-btn span.input-group-btn
......
...@@ -5,7 +5,7 @@ a.list-group-item.post-list.mod-hover-hidden data-post-id=post.id href=post_path ...@@ -5,7 +5,7 @@ a.list-group-item.post-list.mod-hover-hidden data-post-id=post.id href=post_path
.container-fluid .container-fluid
.row .row
.col-xs-10 .col-xs-10
.text-primary #{post.title} h4.text-link #{post.title}
.col-xs-2 .col-xs-2
small.pull-right small.pull-right
##{post.id} ##{post.id}
......
/! view:search/show
.row
h1
span "#{params[:q]}"
span.small - 検索結果
span.small #{@count}
.col-xs-8 role="navigation"
.list-group
- @posts.each do |_post|
= render partial: 'posts/large_item', locals: { post: _post }
.col-xs-4
.panel.panel-default
.panel-heading
h2.panel-title "#{params[:q]}"に関連するタグ
.panel-body.list-group
- @posts.related_tags.each do |_tag|
a.list-group-item href=search_path(q: "##{_tag.name}") = _tag.name
.panel.panel-default
.panel-heading
h2.panel-title "#{params[:q]}"に関連するユーザー
.panel-body.list-group
- @posts.related_authors.each do |_author|
a.list-group-item href=search_path(q: "@#{_author.name}") = _author.name
...@@ -7,6 +7,7 @@ Rendezvous::Application.routes.draw do ...@@ -7,6 +7,7 @@ Rendezvous::Application.routes.draw do
get 'stock' => 'stock#show', as: 'stock' get 'stock' => 'stock#show', as: 'stock'
get 'flow' => 'flow#show', as: 'flow' get 'flow' => 'flow#show', as: 'flow'
get 'search' => 'search#show', as: 'search'
get 'posts/:id/fork' => 'posts#fork', as: 'fork_post' get 'posts/:id/fork' => 'posts#fork', as: 'fork_post'
post 'posts/:id/mail' => 'posts#mail', as: 'mail_post' post 'posts/:id/mail' => 'posts#mail', as: 'mail_post'
......
...@@ -9,6 +9,9 @@ describe FlowController do ...@@ -9,6 +9,9 @@ describe FlowController do
describe "GET 'show'" do describe "GET 'show'" do
it "returns http success" do it "returns http success" do
get 'show' get 'show'
puts '+++++++++++++++++++++++++++++'
p response.body
puts '+++++++++++++++++++++++++++++'
response.should be_success response.should be_success
end end
end end
......
require 'spec_helper'
describe SearchController do
describe "GET 'show'" do
it "returns http success" do
get 'show'
response.should be_success
end
end
end
require 'spec_helper'
describe SearchDecorator do
end
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the SearchHelper. For example:
#
# describe SearchHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
describe SearchHelper do
pending "add some examples to (or delete) #{__FILE__}"
end
require 'spec_helper'
describe "search/show.html.erb" do
pending "add some examples to (or delete) #{__FILE__}"
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment