Class: CategoriesController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /categories POST /categories.xml



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/categories_controller.rb', line 42

def create
  @category = Category.new(params[:category])

  respond_to do |format|
    if @category.save
      flash[:notice] = 'Category was successfully created.'
      format.html { redirect_to(@category) }
      format.xml  { render :xml => @category, :status => :created, :location => @category }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @category.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /categories/1 DELETE /categories/1.xml



76
77
78
79
80
81
82
83
84
# File 'app/controllers/categories_controller.rb', line 76

def destroy
  @category = Category.find(params[:id])
  @category.destroy

  respond_to do |format|
    format.html { redirect_to(categories_url) }
    format.xml  { head :ok }
  end
end

#editObject

GET /categories/1/edit



36
37
38
# File 'app/controllers/categories_controller.rb', line 36

def edit
  @category = Category.find(params[:id])
end

#indexObject

GET /categories GET /categories.xml



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

def index
  @categories = Category.all(:order => "kind, position")

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

#move_downObject



93
94
95
96
97
98
# File 'app/controllers/categories_controller.rb', line 93

def move_down
  @account = Category.find(params[:id])
  @account.move_lower

  redirect_to :action => :index
end

#move_upObject



86
87
88
89
90
91
# File 'app/controllers/categories_controller.rb', line 86

def move_up
  @account = Category.find(params[:id])
  @account.move_higher

  redirect_to :action => :index
end

#newObject

GET /categories/new GET /categories/new.xml



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

def new
  @category = Category.new

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

#showObject

GET /categories/1 GET /categories/1.xml



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

def show
  @category = Category.find(params[:id])

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

#updateObject

PUT /categories/1 PUT /categories/1.xml



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/categories_controller.rb', line 59

def update
  @category = Category.find(params[:id])

  respond_to do |format|
    if @category.update_attributes(params[:category])
      flash[:notice] = 'Category was successfully updated.'
      format.html { redirect_to(@category) }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @category.errors, :status => :unprocessable_entity }
    end
  end
end