Skip to content

Instantly share code, notes, and snippets.

@beloso
Created April 30, 2011 21:12
Show Gist options
  • Save beloso/949999 to your computer and use it in GitHub Desktop.
Save beloso/949999 to your computer and use it in GitHub Desktop.
Users controller
class UsersController < ApplicationController
# GET /users
# GET /users.xml
def index
@users = User.order("(clicks_given - clicks_received) DESC")
session[:current_user] = nil
@title = "Listing Users"
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @users }
end
end
# GET /users/1
# GET /users/1.xml
def show
@user = User.find(params[:id])
@title = "Viewing " + @user.name
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @user }
end
end
# GET /users/new
# GET /users/new.xml
def new
@user = User.new
@title = "Creating User"
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @user }
end
end
# GET /users/1/edit
def edit
@user = User.find(params[:id])
@title = "Editing " + @user.name
end
# POST /users
# POST /users.xml
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
format.html { redirect_to(@user, :notice => 'User was successfully created.') }
format.xml { render :xml => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end
# PUT /users/1
# PUT /users/1.xml
def update
@user = User.find(params[:id])
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to(@user, :notice => 'User was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end
# /users/:id/click
# /users/:id/click.xml
def click
@user = User.find(params[:id])
@title = "Clicking " + @user.name
@users_to_click = User.where("clicks_given - clicks_received >= ?", -5).order("clicks_given - clicks_received DESC")
session[:current_user] ||= User.find(params[:user][:id]);
respond_to do |format|
format.html # click.html.erb
format.xml { render :xml => @user }
end
end
# DELETE /users/1
# DELETE /users/1.xml
def destroy
@user = User.find(params[:id])
@user.destroy
respond_to do |format|
format.html { redirect_to(users_url) }
format.xml { head :ok }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment