Class ListsController
In: app/controllers/lists_controller.rb
Parent: ApplicationController

Methods

create   destroy   edit   index   new   show   update  

Public Instance methods

POST /lists POST /lists.xml

[Source]

    # File app/controllers/lists_controller.rb, line 66
66:   def create
67:     @list = List.new(params[:list])
68:     @list.owner_id = @user.id
69:     respond_to do |format|
70:       if @list.save
71:         flash[:notice] = "List '#{@list.name}' was successfully created."
72:         format.html { redirect_to(@list) }
73:         format.html { render :action => "show" }
74:         format.xml  { render :xml => @list, :status => :created, :location => @list }
75:       else
76:         format.html { render :action => "new" }
77:         format.xml  { render :xml => @list.errors, :status => :unprocessable_entity }
78:       end
79:     end
80:   end

DELETE /lists/1 DELETE /lists/1.xml

[Source]

     # File app/controllers/lists_controller.rb, line 101
101:   def destroy
102:     @list = List.find(params[:id])
103:     
104:     if (@list.owner_id == @user.id)
105:       @list.destroy
106:       flash[:notice] = "List '#{@list.name}' was successfully deleted."
107:     else
108:       flash[:notice] = "You do not have permissions to delete list '#{@list.name}'"
109:     end
110: 
111:     respond_to do |format|
112:       format.html { redirect_to(lists_url) }
113:       format.xml  { head :ok }
114:     end
115:   end

GET /lists/1/edit

[Source]

    # File app/controllers/lists_controller.rb, line 55
55:   def edit
56:     @list = List.find(params[:id])
57:     @items = @list.items
58:     respond_to do |format|
59:       format.html # index.html.erb
60:       format.xml  { render :xml => @list }
61:     end
62:   end

GET /lists GET /lists.xml

[Source]

    # File app/controllers/lists_controller.rb, line 8
 8:   def index
 9:     @lists = List.find_all_by_owner_id(@user.id)
10: 
11:     respond_to do |format|
12:       format.html # index.html.erb
13:       format.xml  { render :xml => @lists }
14:     end
15:   end

GET /lists/new GET /lists/new.xml

[Source]

    # File app/controllers/lists_controller.rb, line 40
40:   def new
41:     @list = List.new
42:     @list.owner_id = @user.id
43:     
44:     @items = Array.new
45:     @items.push(Item.new(:item => "Enter Item Name"))
46:     @list.items = @items
47: 
48:     respond_to do |format|
49:       format.html # new.html.erb
50:       format.xml  { render :xml => @list }
51:     end
52:   end

GET /lists/1 GET /lists/1.xml

[Source]

    # File app/controllers/lists_controller.rb, line 19
19:   def show
20:     begin
21:       @list = List.find_by_id_and_owner_id(params[:id], @user.id)
22:       @items = @list.items
23:     rescue
24:       flash[:notice] = "There are no lists for you that match id=[#{params[:id]}]"
25:     end
26:     
27:     respond_to do |format|
28:       if @list and @items
29:         format.html # show.html.erb
30:         format.xml  { render :xml => @list }
31:       else
32:         format.html { redirect_to( lists_path) }
33:         format.xml  { head :ok }
34:       end
35:     end
36:   end

PUT /lists/1 PUT /lists/1.xml

[Source]

    # File app/controllers/lists_controller.rb, line 84
84:   def update
85:     @list = List.find(params[:id])
86:     
87:     if not (params[:existing_item_attributes] and params[:new_item_attributes])
88:       #@list.remove_items
89:     end
90:     
91:     if @list.update_attributes(params[:list])
92:       flash[:notice] = "List '#{@list.name}' and its items were successfully updated."
93:       redirect_to list_path(@list)
94:     else
95:       render :action => "edit"
96:     end
97:   end

[Validate]