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