Skip to content

Instantly share code, notes, and snippets.

@bertomartin
Forked from Bodacious/users_controller.rb
Created February 8, 2013 19:21
Show Gist options
  • Save bertomartin/4741278 to your computer and use it in GitHub Desktop.
Save bertomartin/4741278 to your computer and use it in GitHub Desktop.
class UsersController < ApplicationController
# This can be moved to ApplicationController if
# every action within the application should respond to these MIME Types
respond_to :html, :json, :xml
def index
respond_with users
end
def show
respond_with user
end
def create
user.save
respond_with user
end
def update
user.update_attributes(params[:user])
respond_with user
end
def destroy
user.destroy
respond_with user
end
private
# Make these helpers available to the view too
helper_method :user, :users
def user
# If the action is new or create...
if @user = params[:action] =~ /new|create/
User.new(params[:user])
else
User.find(params[:id])
end
end
def users
@users = User.all
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment