Skip to content

Instantly share code, notes, and snippets.

@piclez
Created October 21, 2008 00:07
Show Gist options
  • Save piclez/18217 to your computer and use it in GitHub Desktop.
Save piclez/18217 to your computer and use it in GitHub Desktop.
module Admin
class Items < Application
# provides :xml, :yaml, :js
def index
@items = Item.all
display @items
end
def show(id)
@item = Item.get(id)
raise NotFound unless @item
display @item
end
def new
only_provides :html
@item = Item.new
display @item
end
def edit(id)
only_provides :html
@item = Item.get(id)
raise NotFound unless @item
display @item
end
def create(item)
@item = Item.new(item)
if @item.save
redirect url(:admin_item, @item), :message => {:notice => "Item was successfully created"}
else
display @item, :new
end
end
def update(id, item)
@item = Item.get(id)
raise NotFound unless @item
if @item.update_attributes(item)
redirect url(:admin_item, @item)
else
display @item, :edit
end
end
def destroy(id)
@item = Item.get(id)
raise NotFound unless @item
if @item.destroy
redirect url(:admin_items)
else
raise InternalServerError
end
end
end # Items
end # module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment