Skip to content

Commit b307146

Browse files
author
Jeff Dickey
committed
added searching
1 parent 69d7283 commit b307146

File tree

9 files changed

+54
-3
lines changed

9 files changed

+54
-3
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ log/*.log
33
pkg/
44
test/dummy/db/*.sqlite3
55
test/dummy/log/*.log
6+
test/dummy/log/*.lck
7+
test/dummy/solr
68
test/dummy/public/uploads
79
test/dummy/tmp/
810
.sass-cache

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ gem 'carrierwave'
1010
gem "jquery-rails"
1111
gem 'coffee-rails'
1212
gem 'sass-rails'
13+
gem 'sunspot_rails'
1314

1415
group :development, :test do
1516
gem 'sqlite3'
17+
gem 'sunspot_solr'
1618
end

Gemfile.lock

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
GIT
22
remote: git://github.com/dickeytk/mailboxer
3-
revision: 18b7aad4ac06265c952a30f212db6ead1c8cc94a
3+
revision: 5c8cdb8044b6710b5762dec38d17bb883362c075
44
specs:
55
mailboxer (0.5.4)
66
carrierwave (>= 0.5.8)
77
foreigner (>= 0.9.1)
88
rails (>= 3.1.0)
9+
sunspot_rails (>= 1.3.0)
910

1011
PATH
1112
remote: .
@@ -61,7 +62,8 @@ GEM
6162
orm_adapter (~> 0.0.3)
6263
warden (~> 1.1)
6364
erubis (2.7.0)
64-
execjs (1.2.9)
65+
escape (0.0.4)
66+
execjs (1.2.11)
6567
multi_json (~> 1.0)
6668
foreigner (1.1.1)
6769
activerecord (>= 3.0.0)
@@ -78,8 +80,10 @@ GEM
7880
treetop (~> 1.4.8)
7981
mime-types (1.17.2)
8082
multi_json (1.0.4)
83+
nokogiri (1.5.0)
8184
orm_adapter (0.0.5)
8285
polyglot (0.3.3)
86+
pr_geohash (1.0.0)
8387
rack (1.3.5)
8488
rack-cache (1.1)
8589
rack (>= 0.4)
@@ -107,6 +111,8 @@ GEM
107111
rake (0.9.2.2)
108112
rdoc (3.11)
109113
json (~> 1.4)
114+
rsolr (1.0.6)
115+
builder (>= 2.1.2)
110116
sass (3.1.11)
111117
sass-rails (3.1.5)
112118
actionpack (~> 3.1.0)
@@ -121,6 +127,15 @@ GEM
121127
rack (~> 1.0)
122128
tilt (~> 1.1, != 1.3.0)
123129
sqlite3 (1.3.5)
130+
sunspot (1.3.0)
131+
escape (~> 0.0.4)
132+
pr_geohash (~> 1.0)
133+
rsolr (~> 1.0.6)
134+
sunspot_rails (1.3.0)
135+
nokogiri
136+
sunspot (= 1.3.0)
137+
sunspot_solr (1.3.0)
138+
escape (~> 0.0.4)
124139
thor (0.14.6)
125140
tilt (1.3.3)
126141
treetop (1.4.10)
@@ -144,3 +159,5 @@ DEPENDENCIES
144159
sass-rails
145160
simple_form
146161
sqlite3
162+
sunspot_rails
163+
sunspot_solr

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,18 @@ Start the server!
3535
````
3636
$ rails server
3737
````
38+
39+
Enabling Search
40+
===============
41+
42+
To enable search, install the config file
43+
44+
````
45+
$ rails g sunspot_rails:install
46+
````
47+
48+
Run the development solr server
49+
50+
````
51+
$ rake sunspot:solr:start
52+
````

app/assets/stylesheets/messaging/messages.sass

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ nav
6464
color: white
6565
text-align: center
6666
margin-bottom: 40px
67+
form
68+
margin: 10px 0
6769

6870
ul.ui-autocomplete
6971
position: absolute
@@ -136,6 +138,8 @@ h2
136138
padding: 10px 5px
137139
tr
138140
border-bottom: 1px solid #bbb
141+
.unread
142+
font-weight: bold
139143

140144
#reply
141145
margin-top: 10px

app/controllers/messaging/messages_controller.rb

+6
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,11 @@ def untrash
6161
flash[:notice] = "Message untrashed."
6262
redirect_to messages_path(box: 'inbox')
6363
end
64+
65+
def search
66+
@search = params[:search]
67+
@messages = current_user.search_messages(@search)
68+
render :index
69+
end
6470
end
6571
end

app/views/layouts/messaging/application.html.haml

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
= link_to "Trash", messages_path(box: 'trash'), class: 'selected'
5353
-else
5454
= link_to "Trash", messages_path(box: 'trash')
55+
= form_tag search_path do
56+
%input{ type: 'search', placeholder: 'Search', name: 'search' }
5557
#main.grid_10
5658
= yield
5759
#footer

app/views/messaging/messages/index.html.haml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
- if @search
2+
%h2 Search results for '#{@search}'
13
- if @box == 'inbox'
24
%h2 Inbox
35
- if @box == 'sent'
@@ -15,7 +17,7 @@
1517
%th Messages
1618
%th
1719
- @messages.each do |m|
18-
%tr
20+
%tr{ class: "#{ 'unread' if m.is_unread?(current_user) }" }
1921
- unless @box == 'trash'
2022
%td= check_box_tag '', m.id, false, class: 'delete_multiple_checkbox', name: "conversations[]"
2123
%td= link_to m.last_sender, message_path(m)

config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
delete 'trash'
99
end
1010
end
11+
post 'search' => 'messages#search'
1112
root to: 'messages#index'
1213
end

0 commit comments

Comments
 (0)