Skip to content

Instantly share code, notes, and snippets.

@piclez
Created September 28, 2008 20:16
Show Gist options
  • Save piclez/13499 to your computer and use it in GitHub Desktop.
Save piclez/13499 to your computer and use it in GitHub Desktop.
class Contacts < Application
# provides :xml, :yaml, :js
def index
@contacts = Contact.all
display @contacts
end
def show
@contact = Contact.get(params[:id])
raise NotFound unless @contact
display @contact
end
def new
only_provides :html
@contact = Contact.new
render
end
def edit
only_provides :html
@contact = Contact.get(params[:id])
raise NotFound unless @contact
render
end
def create
@contact = Contact.new(params[:contact])
if @contact.save
redirect url(:contact, @contact.id, :message => { :notice => 'Feedback sent successfully!' })
else
render :new
end
end
def update
@contact = Contact.get(params[:id])
raise NotFound unless @contact
if @contact.update_attributes(params[:contact]) || [email protected]?
redirect url(:contact, @contact)
else
raise BadRequest
end
end
def destroy
@contact = Contact.get(params[:id])
raise NotFound unless @contact
if @contact.destroy
redirect url(:contact)
else
raise BadRequest
end
end
end # Contacts
router:
resources :contacts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment