Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added tagged businesses

  • Loading branch information...
commit 2a6a675f36737aa813c6f09e4443f6b7f060142d 1 parent db2b5d1
@excid3 authored
View
5 app/controllers/businesses_controller.rb
@@ -6,6 +6,11 @@ def index
@businesses = Business.order(:name)
end
+ def tagged
+ @tag = params[:tag]
+ @businesses = Business.tagged_with(@tag)
+ end
+
# GET /businesses/1
def show
@business = Business.find(params[:id])
View
3  app/helpers/application_helper.rb
@@ -1,2 +1,5 @@
module ApplicationHelper
+ def tag_links(tags)
+ tags.sort{|a,b|a.name <=> b.name}.collect {|t| link_to t.name, tagged_businesses_path(t.name)}.join(", ").html_safe
+ end
end
View
2  app/views/businesses/index.html.erb
@@ -1,4 +1,4 @@
-<div class="page-header"><h1>Listing businesses</h1></div>
+<div class="page-header"><h1>Businesses</h1></div>
<div class="row">
<div class="span16">
View
2  app/views/businesses/show.html.erb
@@ -3,7 +3,7 @@
<div class="row">
<div class="span10">
<p><%= @business.description %></p>
- <p>Tags: <%= @business.tag_list %></p>
+ <p>Tags: <%= tag_links @business.tags %></p>
</div>
<div class="span6">
<h4>Contact Information</h4>
View
23 app/views/businesses/tagged.html.erb
@@ -0,0 +1,23 @@
+<div class="page-header"><h1>Businesses Tagged With "<%= @tag %>"</h1></div>
+
+<div class="row">
+ <div class="span16">
+ <table id="businesses" class="zebra-striped">
+ <tr>
+ <th>Name</th>
+ <th>Description</th>
+ </tr>
+
+ <% @businesses.each do |business| %>
+ <tr>
+ <td class="span3"><%= link_to business.name, business %></td>
+ <td class="span13"><%= business.description %></td>
+ </tr>
+ <% end %>
+ </table>
+ </div>
+</div>
+
+<script type="text/javascript">
+</script>
+
View
7 config/routes.rb
@@ -2,7 +2,12 @@
devise_for :users
- resources :businesses
+ resources :businesses do
+ collection do
+ get "tagged/:tag" => "businesses#tagged", :as => :tagged
+ end
+ end
+
root :to => "main#index"
# The priority is based upon order of creation:
Please sign in to comment.
Something went wrong with that request. Please try again.