Created
March 26, 2013 02:04
-
-
Save samuelkobe/5242539 to your computer and use it in GitHub Desktop.
users
This file contains 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 | |
def index | |
@users = User.order(:id) | |
respond_to do |format| | |
format.html | |
format.csv { send_data @users.to_csv } | |
format.xls # { send_data @users.to_csv(col_sep: "\t") } | |
end | |
end | |
def show | |
@user = User.find(params[:id]) | |
respond_to do |format| | |
format.html # show.html.erb | |
format.json { render json: @user } | |
end | |
end | |
def new | |
@user = User.new | |
respond_to do |format| | |
format.html # new.html.erb | |
format.json { render json: @user } | |
end | |
end | |
def edit | |
@user = User.find(params[:id]) | |
end | |
def create | |
@user = User.new(params[:user]) | |
respond_to do |format| | |
if @user.save | |
UserMailer.registration_confirmation(@user).deliver | |
format.html { redirect_to @user, notice: 'User was successfully created.' } | |
format.json { render json: @user, status: :created, location: @user } | |
else | |
format.html { render action: "new" } | |
format.json { render json: @user.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
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.json { head :no_content } | |
else | |
format.html { render action: "edit" } | |
format.json { render json: @user.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
def destroy | |
@user = User.find(params[:id]) | |
@user.destroy | |
respond_to do |format| | |
format.html { redirect_to users_url } | |
format.json { head :no_content } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment