Created
September 28, 2008 20:16
-
-
Save piclez/13499 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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