Skip to content

Instantly share code, notes, and snippets.

@MikeSilvis
Created May 8, 2012 04:09
Show Gist options
  • Save MikeSilvis/2632508 to your computer and use it in GitHub Desktop.
Save MikeSilvis/2632508 to your computer and use it in GitHub Desktop.
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
@j3j3
Copy link

j3j3 commented May 16, 2012

What an amazing gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment