Class: Discussion::CommentsController

Inherits:
InheritedResources::Base
  • Object
show all
Defined in:
app/controllers/discussion/comments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/discussion/comments_controller.rb', line 24

def create
  build_resource
  respond_to do |format|
    if @comment.save
      format.html { redirect_to :back }
      format.js { collection }
      format.json { render json: @comment, status: :created, location: @comment }
    else
      format.html { render action: "new" }
      format.json { render json: @comment.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject



50
51
52
53
54
55
56
57
# File 'app/controllers/discussion/comments_controller.rb', line 50

def destroy
  @comment.destroy
  respond_to do |format|
    format.html { redirect_to :back }
    format.js { collection }
    format.json { head :no_content }
  end
end

#editObject



21
22
# File 'app/controllers/discussion/comments_controller.rb', line 21

def edit
end

#indexObject



10
11
12
13
14
# File 'app/controllers/discussion/comments_controller.rb', line 10

def index
  @comments = collection
  respond_with(@comments)
  @comments.each { |c| c.read_by!(current_user) }
end

#newObject



16
17
18
19
# File 'app/controllers/discussion/comments_controller.rb', line 16

def new
  build_resource
  respond_with(@comment)
end

#updateObject



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

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