Created
October 21, 2008 00:07
-
-
Save piclez/18217 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
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