items_controller.rb
1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class ItemsController < ApplicationController
# GET /items
# GET /items.xml
def index
@items = Item.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @items }
end
end
# GET /items/1
# GET /items/1.xml
def show
@item = Item.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @item }
end
end
# GET /items/new
# GET /items/new.xml
def new
@item = Item.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @item }
end
end
# GET /items/1/edit
def edit
@item = Item.find(params[:id])
end
# POST /items
# POST /items.xml
def create
@item = Item.new(params[:item])
respond_to do |format|
if @item.save
flash[:notice] = 'Item was successfully created.'
format.html { redirect_to(@item) }
format.xml { render :xml => @item, :status => :created, :location => @item }
else
format.html { render :action => "new" }
format.xml { render :xml => @item.errors, :status => :unprocessable_entity }
end
end
end
# PUT /items/1
# PUT /items/1.xml
def update
@item = Item.find(params[:id])
respond_to do |format|
if @item.update_attributes(params[:item])
flash[:notice] = 'Item was successfully updated.'
format.html { redirect_to(@item) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @item.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /items/1
# DELETE /items/1.xml
def destroy
@item = Item.find(params[:id])
@item.destroy
respond_to do |format|
format.html { redirect_to(items_url) }
format.xml { head :ok }
end
end
end