Created
May 8, 2012 04:09
-
-
Save MikeSilvis/2632508 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UsersController < ApplicationController | |
before_filter :current_user | |
before_filter :find_user, :only => [:edit, :update, :destroy, :show] | |
def show | |
end | |
def new | |
@user = User.new | |
end | |
def create | |
@user = User.new(params[:user]) | |
if @user.save | |
redirect_to users_path, :notice => 'Your preferences has been saved' | |
else | |
redirect_to users_path, :error => 'An error has occurred' | |
end | |
end | |
def edit | |
end | |
def update | |
if @user.update_attributes(params[:user]) | |
redirect_to users_path, :notice => 'The users preferences has been updated' | |
else | |
redirect_to users_path, :notice => 'Sorry, the update was unsuccesful' | |
end | |
end | |
def destroy | |
if @user.destroy | |
redirect_to users_path, :notice => 'The requested account has been removed' | |
end | |
end | |
private | |
def find_user | |
@user = User.find(params[:id]) | |
end | |
def current_user | |
@current_user = User.find(session[:user_id]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What an amazing gist.