Skip to content

Commit

Permalink
added tags report
Browse files Browse the repository at this point in the history
  • Loading branch information
JuddL333 committed Jul 22, 2013
1 parent bbd1dad commit 75e130a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ApplicationController < ActionController::Base
protect_from_forgery

helper_method :current_user, :logged_in?
helper_method :current_user, :logged_in?, :current_user_is_admin?

private

Expand All @@ -12,4 +12,9 @@ def current_user
def logged_in?
@current_user
end

def current_user_is_admin?
return false if current_user.nil? || !current_user.admin?
true
end
end
13 changes: 13 additions & 0 deletions app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
class TagsController < ApplicationController
before_filter :ensure_admin, only: [:index]

def index
@tags = Tag.all
end

def show
@tag = Tag.find(params[:id])
Expand All @@ -10,4 +15,12 @@ def show
end
end

private

def ensure_admin
if current_user.nil? || !current_user.admin?
redirect_to root_url
end
end

end
5 changes: 5 additions & 0 deletions app/views/layouts/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ html
ul.dropdown-menu

li= link_to(current_user.twitter_handle, '#')
- if current_user_is_admin?
li.divider
li= link_to "Tags Report", tags_path


li.divider
li= link_to "Sign out", "/sessions/destroy", method: 'delete'
- else
Expand Down
12 changes: 12 additions & 0 deletions app/views/tags/index.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
h1 Tags Overview

table.table.table-striped
thead
tr
td Name
td Number of Tweets
tbody
- @tags.each do |tag|
tr
td= tag.name
td= tag.stories.count
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

get 'sessions/create'

resources :tags, only: :show
resources :tags, only: [:show, :index]
resources :events, only: :index

resources :posts do
Expand Down

0 comments on commit 75e130a

Please sign in to comment.