Class: CommentsController

Inherits:
ApplicationController show all
Includes:
Applicat::Mvc::Controller::Resource
Defined in:
app/controllers/comments_controller.rb

Instance Method Summary collapse

Methods included from Applicat::Mvc::Controller::Resource

included

Methods inherited from ApplicationController

#current_ability

Methods included from Voluntary::V1::BaseController

#parent, #voluntary_application_javascripts, #voluntary_application_repository_path, #voluntary_application_stylesheets

Methods included from Applicat::Mvc::Controller

included

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/comments_controller.rb', line 23

def create
  @comment = Comment.new(params[:comment])
  @comment.user_id = current_user.id
  
  if @comment.save
    redirect_to @comment.commentable, notice: t('general.form.successfully_created')
  else
    render :new
  end
end

#destroyObject



48
49
50
51
52
# File 'app/controllers/comments_controller.rb', line 48

def destroy
  @comment = Comment.find(params[:id])
  @comment.destroy
  redirect_to comments_url, notice: t('general.form.destroyed')
end

#editObject



34
35
36
# File 'app/controllers/comments_controller.rb', line 34

def edit
  @comment = Comment.find(params[:id])
end

#indexObject



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

def index
  @comments = Comment.includes(:commentable, :user).all
end

#newObject



18
19
20
21
# File 'app/controllers/comments_controller.rb', line 18

def new
  @comment = Comment.new(params[:comment])
  @comment.commentable = @commentable
end

#resourceObject



54
55
56
# File 'app/controllers/comments_controller.rb', line 54

def resource
  @comment
end

#showObject



14
15
16
# File 'app/controllers/comments_controller.rb', line 14

def show
  @comment = Comment.includes(:commentable, :user).find(params[:id])
end

#updateObject



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

def update
  @comment = Comment.find(params[:id])
  
  if @comment.update_attributes(params[:comment])
    redirect_to @comment.commentable, notice: t('general.form.successfully_updated')
  else
    render :edit
  end
end