Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
73 lines (62 sloc) 1.43 KB
class ItemsController < ApplicationController
# GET /items
# GET /items.json
#respond_to :json
respond_to :json
def index
@items = Item.all
respond_with(@items)
end
# GET /items/1
# GET /items/1.json
def show
@item = Item.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @item }
end
end
# GET /items/new
# GET /items/new.json
def new
@item = Item.new
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @item }
end
end
# GET /items/1/edit
def edit
@item = Item.find(params[:id])
end
# POST /items
# POST /items.json
def create
Item.create!(params[:item])
redirect_to items_url
end
# PUT /items/1
# PUT /items/1.json
def update
@item = Item.find(params[:id])
respond_to do |format|
if @item.update_attributes(params[:item])
format.html { redirect_to @item, :notice => 'Item was successfully updated.' }
format.json { head :ok }
else
format.html { render :action => "edit" }
format.json { render :json => @item.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /items/1
# DELETE /items/1.json
def destroy
@item = Item.find(params[:id])
@item.destroy
respond_to do |format|
format.html { redirect_to items_url }
format.json { head :ok }
end
end
end
Something went wrong with that request. Please try again.