Skip to content

Commit

Permalink
rails_apps_composer: controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEricMiller committed Mar 21, 2013
1 parent d0effab commit 364fce2
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/home.js.coffee
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/home.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the home controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
class ApplicationController < ActionController::Base
protect_from_forgery

rescue_from CanCan::AccessDenied do |exception|
redirect_to root_path, :alert => exception.message
end

end
5 changes: 5 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class HomeController < ApplicationController
def index
@users = User.all
end
end
33 changes: 33 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class UsersController < ApplicationController
before_filter :authenticate_user!

def index
authorize! :index, @user, :message => 'Not authorized as an administrator.'
@users = User.all
end

def show
@user = User.find(params[:id])
end

def update
authorize! :update, @user, :message => 'Not authorized as an administrator.'
@user = User.find(params[:id])
if @user.update_attributes(params[:user], :as => :admin)
redirect_to users_path, :notice => "User updated."
else
redirect_to users_path, :alert => "Unable to update user."
end
end

def destroy
authorize! :destroy, @user, :message => 'Not authorized as an administrator.'
user = User.find(params[:id])
unless user == current_user
user.destroy
redirect_to users_path, :notice => "User deleted."
else
redirect_to users_path, :notice => "Can't delete yourself."
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/home_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module HomeHelper
end
2 changes: 2 additions & 0 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Home#index</h1>
<p>Find me in app/views/home/index.html.erb</p>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
RailsPrelaunchSignup::Application.routes.draw do
get "home/index"

devise_for :users

# The priority is based upon order of creation:
Expand Down
12 changes: 12 additions & 0 deletions spec/controllers/home_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'spec_helper'

describe HomeController do

describe "GET 'index'" do
it "returns http success" do
get 'index'
response.should be_success
end
end

end

0 comments on commit 364fce2

Please sign in to comment.