Browse files

Merge pull request #4 from waynegraham/search

Adds simple search through will_paginate
  • Loading branch information...
2 parents 1f9946d + 9f31507 commit 77b71020a1064911a79d5c0bb522e575341cdd75 @nowviskie committed Dec 15, 2011
View
2 Gemfile
@@ -15,7 +15,7 @@ group :assets do
end
gem 'jquery-rails'
-
+gem 'will_paginate', '~>3.0.2'
# Use unicorn as the web server
# gem 'unicorn'
View
2 Gemfile.lock
@@ -123,6 +123,7 @@ GEM
uglifier (1.2.0)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
+ will_paginate (3.0.2)
PLATFORMS
ruby
@@ -138,3 +139,4 @@ DEPENDENCIES
sqlite3
turn
uglifier
+ will_paginate (~> 3.0.2)
View
3 app/controllers/topics_controller.rb
@@ -2,7 +2,8 @@ class TopicsController < ApplicationController
# GET /topics
# GET /topics.json
def index
- @topics = Topic.all
+
+ @topics = Topic.search(params[:search], params[:page])
respond_to do |format|
format.html # index.html.erb
View
5 app/models/topic.rb
@@ -1,4 +1,9 @@
class Topic < ActiveRecord::Base
has_many :votes
+ def self.search(search, page)
+ paginate :per_page => 5, :page => page,
+ :conditions => ['title like ?', "%#{search}%"], :order => 'title'
+ end
+
end
View
6 app/views/layouts/application.html.erb
@@ -48,6 +48,12 @@ a:hover {
</head>
<body>
<div class="container">
+ <%= form_tag request.path, :method => 'get' do %>
+ <% content_tag :label do %>
+ Singer:
+ <%= text_field_tag :search, params[:search] %>
+ <% end %>
+<% end %>
<%= yield %>
<div class="footer"><p><em>(Get the <a href="http://github.com/nowviskie/Suggestitron">code</a>.)</em></p></div>
</div>
View
4 app/views/topics/index.html.erb
@@ -23,5 +23,9 @@
<h3><%= link_to 'Who\'s Up Next?', new_topic_path %></h3>
+<%= will_paginate @topics %>
+
+
+
<p><em>Happy Holidays from your friends at the <a href="http://scholarslab.org"><img src="http://nowviskie.org/images/slab-logo.png" align="center"/></a></em></p>
</div>

0 comments on commit 77b7102

Please sign in to comment.