Permalink
Browse files

add admin field

  • Loading branch information...
1 parent a6ddc7f commit 1203a9ad63b0a1be55106694970b03341baf167c @yocha committed Apr 29, 2012
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
+// Place all the styles related to the tasks controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,39 @@
+class TasksController < ApplicationController
+ before_filter :check_admin, :except => [:index]
+
+ def check_admin
+ unless current_user.admin?
+ flash[:notice] = "Sorry! You don't have access."
+ redirect_to(root_path)
+ end
+ end
+
+ def index
+ @tasks = Task.all
+ respond_to do |format|
+ format.html
+ format.json { render json: @task }
+ end
+ end
+
+ def show
+ @task = Task.find(params[:id])
+
+ respond_to do |format|
+ format.html
+ format.json {render json: @task}
+ end
+ end
+
+ def new
+
+ end
+
+ def create
+
+ end
+
+ def update
+
+ end
+end
@@ -0,0 +1,2 @@
+module TasksHelper
+end
@@ -23,7 +23,8 @@
<a class="brand" href='#'>AgileBaby</a>
<div class="nav-collapse">
<ul class="nav">
- <li><%= link_to "Browse Events", events_path %></li>
+ <li><%= link_to "Events", events_path %></li>
+ <li><%= link_to "Tasks", tasks_path %></li>
</ul>
<ul class="nav pull-right">
<% if user_signed_in? %>
@@ -0,0 +1,38 @@
+<%- model_class = Task.new.class -%>
+<h1><%=t '.title', :default => model_class.model_name.human.pluralize %></h1>
+<table class="table table-striped">
+ <thead>
+ <tr>
+ <th><%= model_class.human_attribute_name(:id) %></th>
+ <th><%= model_class.human_attribute_name(:name) %></th>
+ <% if current_user.admin? %>
+ <th><%=t '.actions', :default => t("helpers.actions") %></th>
+ <% end %>
+ </tr>
+ </thead>
+ <tbody>
+ <% @tasks.each do |task| %>
+ <tr>
+ <td><%= link_to task.id, task_path(task) %></td>
+ <td><%= task.name %></td>
+ <% if current_user.admin? %>
+ <td>
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
+ edit_task_path(task), :class => 'btn btn-mini' %>
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
+ task_path(task),
+ :method => :delete,
+ :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
+ :class => 'btn btn-mini btn-danger' %>
+ </td>
+ <% end %>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
+
+<% if current_user.admin? %>
+ <%= link_to t('.new', :default => t("helpers.links.new")),
+ new_task_path,
+ :class => 'btn btn-primary' %>
+<% end %>
View
@@ -2,6 +2,7 @@
devise_for :users
resources :events
+ resources :tasks
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -0,0 +1,6 @@
+class AddAdminToUsers < ActiveRecord::Migration
+ def change
+ add_column :users, :admin, :boolean, default: false
+
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120428034604) do
+ActiveRecord::Schema.define(:version => 20120429064445) do
create_table "events", :force => true do |t|
t.integer "task_id"
@@ -30,9 +30,9 @@
end
create_table "users", :force => true do |t|
- t.string "email", :default => "", :null => false
- t.string "name", :default => "", :null => false
- t.string "encrypted_password", :default => "", :null => false
+ t.string "email", :default => "", :null => false
+ t.string "name", :default => "", :null => false
+ t.string "encrypted_password", :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
@@ -41,8 +41,9 @@
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.boolean "admin", :default => false
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe TasksController do
+
+end
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the TasksHelper. For example:
+#
+# describe TasksHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe TasksHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end

0 comments on commit 1203a9a

Please sign in to comment.