Class: ItemsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/items_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /items POST /items.xml



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/items_controller.rb', line 46

def create
  @item = Item.new(params[:item])
  @item.type = (@item.category ? @item.category.kind : "Move")
  @accounts = Account.all
  @categories = Category.all

  respond_to do |format|
    if @item.save
      format.html {
        flash[:notice] = 'Item was successfully created.'
        redirect_to(@item) 
      }
      format.xml  { render :xml => @item, :status => :created, :location => @item }
      format.json { render :text => "['ok', #{@item.id}]" }
    else
      @item.errors.each{|err| logger.debug err.inspect}
      format.html { render :action => "new" }
      format.xml  { render :xml => @item.errors, :status => :unprocessable_entity }
      format.json { render :text => "['error']" }
    end
  end
end

#destroyObject

DELETE /items/1 DELETE /items/1.xml



95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/items_controller.rb', line 95

def destroy
  @item = Item.find(params[:id])
  @item.destroy

  respond_to do |format|
    format.html { redirect_to(items_url) }
    format.xml  { head :ok }
    format.json { render :text => "['ok']" }
  end
end

#editObject

GET /items/1/edit



38
39
40
41
42
# File 'app/controllers/items_controller.rb', line 38

def edit
  @item = Item.find(params[:id])
  @accounts = Account.all
  @categories = Category.all
end

#indexObject

GET /items GET /items.xml



4
5
6
7
8
9
10
11
# File 'app/controllers/items_controller.rb', line 4

def index
  @items = Item.all(:order => "updated_at DESC")

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @items }
  end
end

#newObject

GET /items/new GET /items/new.xml



26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/items_controller.rb', line 26

def new
  @item = Item.new
  @accounts = Account.all
  @categories = Category.all

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @item }
  end
end

#showObject

GET /items/1 GET /items/1.xml



15
16
17
18
19
20
21
22
# File 'app/controllers/items_controller.rb', line 15

def show
  @item = Item.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @item }
  end
end

#updateObject

PUT /items/1 PUT /items/1.xml



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/items_controller.rb', line 71

def update
  @item = Item.find(params[:id])
  @accounts = Account.all
  @categories = Category.all

  respond_to do |format|
    if @item.update_attributes(params[:item])
      format.html { 
        flash[:notice] = 'Item was successfully updated.'
        redirect_to(@item) 
      }
      format.xml  { head :ok }
      format.json { render :text => "['ok']" }
    else
      @item.errors.each{|err| logger.debug err.inspect}
      format.html { render :action => "edit" }
      format.xml  { render :xml => @item.errors, :status => :unprocessable_entity }
      format.json { render :text => "['error']" }
    end
  end
end