Skip to content

Instantly share code, notes, and snippets.

@mhfs
Created October 28, 2009 13:06
Show Gist options
  • Save mhfs/220476 to your computer and use it in GitHub Desktop.
Save mhfs/220476 to your computer and use it in GitHub Desktop.
class ContactsController < ApplicationController
def index
@contacts = current_user.contacts.paginate :page => params[:page]
end
def show
@contact = current_user.contacts.find(params[:id])
end
def new
@contact = Contact.new
end
def create
@contact = current_user.contacts.build(params[:contact])
if @contact.save
flash[:notice] = "Successfully created contact."
redirect_to @contact
else
render :action => 'new'
end
end
def edit
@contact = Contact.find(params[:id])
end
def update
@contact = current_user.contacts.find(params[:id])
if @contact.update_attributes(params[:contact])
flash[:notice] = "Successfully updated contact."
redirect_to @contact
else
render :action => 'edit'
end
end
def destroy
@contact = current_user.contacts.find(params[:id])
@contact.destroy
flash[:notice] = "Successfully destroyed contact."
redirect_to contacts_url
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment