Class: Opinio::CommentsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Opinio::Controllers::InternalHelpers, Opinio::Controllers::Replies
Defined in:
app/controllers/opinio/comments_controller.rb

Instance Method Summary collapse

Methods included from Opinio::Controllers::Replies

#reply

Methods included from Opinio::Controllers::InternalHelpers

#custom_resource_identifier, #resource, #resource_by_params, #resource_name, #set_flash

Instance Method Details

#createObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/opinio/comments_controller.rb', line 9

def create
  @comment = resource.comments.build(params[:comment])
  @comment.owner = current_commenter
  if @comment.save
    flash_area = :notice
    message = t('opinio.messages.comment_sent')
  else
    flash_area = :error
    message = t('opinio.messages.comment_sending_error')
  end

  respond_to do |format|
    format.js
    format.html do
      set_flash(flash_area, message)
      redirect_to(opinio_after_create_path(resource))
    end
  end
end

#destroyObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/opinio/comments_controller.rb', line 29

def destroy
  @comment = Opinio.model_name.constantize.find(params[:id])

  if can_destroy_opinio?(@comment)
    @comment.destroy
    set_flash(:notice, t('opinio.messages.comment_destroyed'))
  else
    #flash[:error]  = I18n.translate('opinio.comment.not_permitted', :default => "Not permitted")
    logger.warn "user #{current_commenter} tried to remove a comment from another user #{@comment.owner.id}"
    render :text => "unauthorized", :status => 401 and return
  end

  respond_to do |format|
    format.js
    format.html { redirect_to( opinio_after_destroy_path(@comment) ) }
  end
end

#indexObject



5
6
7
# File 'app/controllers/opinio/comments_controller.rb', line 5

def index
  @comments = resource.comments.page(params[:page])
end