Skip to content

Commit

Permalink
Add search form
Browse files Browse the repository at this point in the history
  • Loading branch information
twata701 committed Feb 25, 2014
1 parent d33e564 commit 99a391d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -56,3 +56,4 @@ gem 'omniauth-twitter'
# manage environment specific
gem 'rails_config'

gem 'ransack'
7 changes: 7 additions & 0 deletions Gemfile.lock
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -159,6 +165,7 @@ DEPENDENCIES
omniauth-twitter
rails (= 4.0.0)
rails_config
ransack
sass-rails (~> 4.0.0)
sdoc
sqlite3
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/tweets_controller.rb
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions app/views/layouts/tweets.html.erb
Expand Up @@ -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>
Expand Down
7 changes: 7 additions & 0 deletions app/views/tweets/search.html.erb
@@ -0,0 +1,7 @@
<h1><%= params[:q] %>」の検索結果</h1>

<%= render(@tweets) %>
<% if @tweets.count == 0 %>
<p><%= params[:q] %>に一致するツイートはありませんでした。</p>
<% end %>
<%= paginate (@tweets) %>
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -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

Expand Down

0 comments on commit 99a391d

Please sign in to comment.