-
-
Save bertomartin/4741278 to your computer and use it in GitHub Desktop.
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 | |
# 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