Permalink
Browse files

Add search form

  • Loading branch information...
twata701 committed Feb 25, 2014
1 parent d33e564 commit 99a391d10ca5c69ae136d295590253a5c35b0a00
Showing with 31 additions and 0 deletions.
  1. +1 −0 Gemfile
  2. +7 −0 Gemfile.lock
  3. +8 −0 app/controllers/tweets_controller.rb
  4. +7 −0 app/views/layouts/tweets.html.erb
  5. +7 −0 app/views/tweets/search.html.erb
  6. +1 −0 config/routes.rb
View
@@ -56,3 +56,4 @@ gem 'omniauth-twitter'
# manage environment specific
gem 'rails_config'
gem 'ransack'
View
@@ -81,6 +81,8 @@ GEM
multi_json (~> 1.3)
omniauth-oauth (~> 1.0)
orm_adapter (0.5.0)
polyamorous (0.6.4)
activerecord (>= 3.0)
polyglot (0.3.3)
rack (1.5.2)
rack-test (0.6.2)
@@ -101,6 +103,10 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.1.1)
ransack (1.1.0)
actionpack (>= 3.0)
activerecord (>= 3.0)
polyamorous (~> 0.6.0)
rdoc (4.1.1)
json (~> 1.4)
ref (1.0.5)
@@ -159,6 +165,7 @@ DEPENDENCIES
omniauth-twitter
rails (= 4.0.0)
rails_config
ransack
sass-rails (~> 4.0.0)
sdoc
sqlite3
@@ -91,6 +91,14 @@ def archives
.page params[:page]
end
# GET /tweets/search/keyword
def search
@tweets = @user.tweet
.search(:text_cont => params[:q]).result
.order(:id)
.page params[:page]
end
private
# Use callbacks to share common setup or constraints between actions.
def set_tweet
@@ -68,6 +68,13 @@
<div class="span3">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Search</li>
<%= form_tag(search_tweets_path, :method => "get") do %>
<div class="input-append">
<%= text_field_tag("q", params[:q], :class => "span9") %>
<%= submit_tag "検索", :class => "btn"%>
</div>
<% end %>
<li class="nav-header">Archives</li>
<% @archives.each do |yyyymm, count| %>
<li><%= link_to ymconv(yyyymm, count.to_s) , archives_tweets_path(:yyyymm => yyyymm)%><li>
@@ -0,0 +1,7 @@
<h1>「<%= params[:q] %>」の検索結果</h1>
<%= render(@tweets) %>
<% if @tweets.count == 0 %>
<p><%= params[:q] %>に一致するツイートはありませんでした。</p>
<% end %>
<%= paginate (@tweets) %>
View
@@ -4,6 +4,7 @@
get 'import_csv_new'
post 'import_csv'
get 'archives/:yyyymm', :action => :archives, :as =>'archives'
get 'search', :action => :search, :as =>'search'
end
end

0 comments on commit 99a391d

Please sign in to comment.