diff options
author | rhenium <re4k@re4k.info> | 2013-05-31 23:37:51 +0900 |
---|---|---|
committer | rhenium <re4k@re4k.info> | 2013-05-31 23:37:51 +0900 |
commit | 90abe9df522b3fafdf83e0578d6ee3fac58905a5 (patch) | |
tree | 3818b5571ff997228442c4e3ad2eb0b59b8a6efc | |
parent | 85424b0c01fe508ffdfa8e38e4423853986d7451 (diff) | |
download | aclog-90abe9df522b3fafdf83e0578d6ee3fac58905a5.tar.gz |
fix search#search error when no "query" parameter
-rw-r--r-- | app/controllers/search_controller.rb | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index aa13660..96396c8 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -3,16 +3,16 @@ class SearchController < ApplicationController def search @caption = "search" - @tweets = Tweet.where(parse_query(params[:query])).reacted.recent(7).order_by_id.list(params, force_page: true) + @tweets = Tweet.where(parse_query(params[:query] || "")).reacted.recent(7).order_by_id.list(params, force_page: true) end private def parse_query(input) str = input.dup strings = [] - str.gsub!(/"((?:\\"|[^"])*?)"/) {|m| strings << $1; "##{strings.size - 1}" } + str.gsub!(/"((?:\\"|[^"])*?)"/) {|m| strings << $1; " ##{strings.size - 1} " } groups = [] - while str.sub!(/\(([^()]*?)\)/) {|m| groups << $1; "$#{groups.size - 1}" }; end + while str.sub!(/\(([^()]*?)\)/) {|m| groups << $1; " $#{groups.size - 1} " }; end conv = -> s do s.scan(/\S+(?: OR \S+)*/).map {|co| |