Commit b286fc3d
Changed files (3)
app
controllers
views
search
spec
controllers
app/controllers/search_controller.rb
@@ -6,6 +6,7 @@ class SearchController < ApplicationController
else
@creations = Creation.includes(:user).search(@search).page(params[:page]).per(100)
@members = User.includes(:avatar).where("upper(name) like upper(?)", "%#{@search}%")
+ @tutorials = Tutorial.where("upper(heading) like upper(?) OR upper(description) like upper(?)", "%#{@search}%", "%#{@search}%")
end
end
end
app/views/search/index.html.erb
@@ -4,14 +4,16 @@
<% if @creations.any? %>
<table class="table table-striped">
<thead>
+ <th></th>
<th>Creations</th>
<th>Artist</th>
<th>Name</th>
<th>Description</th>
</thead>
<tbody>
- <% @creations.each do |creation| %>
+ <% @creations.each_with_index do |creation, index| %>
<tr>
+ <td><%= index %></td>
<td><a href="<%= url_for creation_path(creation) %>"><%= image_tag creation.primary_image.image.thumb.url, :class=> 'thumbnail', :style => "width:65px" %></a></td>
<td><%= link_to creation.user.name, profile_path(creation.user) %></td>
<td><%= creation.name %></td>
@@ -26,14 +28,16 @@
<% if @members.any? %>
<table class="table table-striped">
<thead>
+ <th></th>
<th>Artists</th>
<th>Name</th>
</thead>
<tbody>
- <% @members.each do |artist| %>
+ <% @members.each_with_index do |artist, index| %>
<tr>
+ <td><%= index %></td>
<td><a href="<%= url_for profile_path(artist) %>"><%= avatar_for(artist, :size => 65) %></a></td>
- <td><%= artist.name %></td>
+ <td><%= link_to artist.name, profile_path(artist) %></td>
<td><%= link_to artist.website if artist.website %></td>
<td><%= link_to artist.twitter, "https://twitter.com/#{artist.twitter}" if artist.twitter.present? %></td>
<td><%= link_to artist.facebook if artist.facebook %></td>
@@ -45,5 +49,25 @@
<% else %>
<p>No artists found.</p>
<% end %>
+ <% if @tutorials.any? %>
+ <table class="table table-striped">
+ <thead>
+ <th></th>
+ <th>Tutorials</th>
+ <th>Name</th>
+ </thead>
+ <tbody>
+ <% @tutorials.each_with_index do |tutorial, index| %>
+ <tr>
+ <td><%= index %></td>
+ <td><%= link_to tutorial.heading, tutorial_path(tutorial) %></td>
+ <td><%= tutorial.description %></td>
+ </tr>
+ <% end %>
+ </tbody>
+ </table>
+ <% else %>
+ <p>No tutorials found.</p>
+ <% end %>
</div>
</div>
spec/controllers/search_controller_spec.rb
@@ -14,6 +14,8 @@ describe SearchController do
let!(:bob) { FactoryGirl.create(:user, :name => 'bob') }
let!(:cake) { FactoryGirl.create(:creation, :name => 'cake') }
let!(:donut) { FactoryGirl.create(:creation, :name => 'donut') }
+ let!(:tutorial) { FactoryGirl.create(:tutorial, :description => 'cake') }
+ let!(:other_tutorial) { FactoryGirl.create(:tutorial, :description => 'donut') }
before { get :index, { :q => 'cake' } }
@@ -36,6 +38,14 @@ describe SearchController do
it "should not include makers with names that do not match" do
assigns(:members).should_not include(bob)
end
+
+ it "should return all tutorials that match" do
+ assigns(:tutorials).should include(tutorial)
+ end
+
+ it "should not return tutorials that do not match" do
+ assigns(:tutorials).should_not include(other_tutorial)
+ end
end
end
end