Class: CommentsController

Inherits:
ApplicationController show all
Defined in:
tmp/mongoid-demo/rails/app/controllers/comments_controller.rb,
tmp/mongoid-demo/rails-api/app/controllers/comments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /comments



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'tmp/mongoid-demo/rails/app/controllers/comments_controller.rb', line 26

def create
  @comment = Comment.new(comment_params)

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

#destroyObject

DELETE /comments/1



56
57
58
59
60
61
62
# File 'tmp/mongoid-demo/rails/app/controllers/comments_controller.rb', line 56

def destroy
  @comment.destroy
  respond_to do |format|
    format.html { redirect_to comments_url, notice: 'Comment was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#editObject

GET /comments/1/edit



21
22
# File 'tmp/mongoid-demo/rails/app/controllers/comments_controller.rb', line 21

def edit
end

#indexObject

GET /comments



6
7
8
# File 'tmp/mongoid-demo/rails/app/controllers/comments_controller.rb', line 6

def index
  @comments = Comment.all
end

#newObject

GET /comments/new



16
17
18
# File 'tmp/mongoid-demo/rails/app/controllers/comments_controller.rb', line 16

def new
  @comment = Comment.new
end

#showObject

GET /comments/1



12
13
# File 'tmp/mongoid-demo/rails/app/controllers/comments_controller.rb', line 12

def show
end

#updateObject

PATCH/PUT /comments/1



42
43
44
45
46
47
48
49
50
51
52
# File 'tmp/mongoid-demo/rails/app/controllers/comments_controller.rb', line 42

def update
  respond_to do |format|
    if @comment.update(comment_params)
      format.html { redirect_to @comment, notice: 'Comment was successfully updated.' }
      format.json { render :show, status: :ok, location: @comment }
    else
      format.html { render :edit }
      format.json { render json: @comment.errors, status: :unprocessable_entity }
    end
  end
end