Class: CategoriesController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /categories POST /categories.json



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/categories_controller.rb', line 36

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

  respond_to do |format|
    if @category.save
      format.html { redirect_to @category, notice: 'Category was successfully created.' }
      format.json { render json: @category, status: :created, location: @category }
    else
      format.html { render action: "new" }
      format.json { render json: @category.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /categories/1 DELETE /categories/1.json



68
69
70
71
72
73
74
75
76
# File 'app/controllers/categories_controller.rb', line 68

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

  respond_to do |format|
    format.html { redirect_to categories_url }
    format.json { head :ok }
  end
end

#editObject

GET /categories/1/edit



30
31
32
# File 'app/controllers/categories_controller.rb', line 30

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

#indexObject

GET /categories GET /categories.json



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

def index
  @categories = Category.all

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

#newObject

GET /categories/new GET /categories/new.json



20
21
22
23
24
25
26
27
# File 'app/controllers/categories_controller.rb', line 20

def new
  @category = Category.new

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

#showObject



13
14
15
# File 'app/controllers/categories_controller.rb', line 13

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

#updateObject

PUT /categories/1 PUT /categories/1.json



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/categories_controller.rb', line 52

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

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