Class: Opinio::CommentsController
Instance Method Summary
collapse
#reply
#custom_resource_identifier, #resource, #resource_by_params, #resource_name, #set_flash
Instance Method Details
#create ⇒ Object
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..build(params[:comment])
@comment.owner = send(Opinio.current_user_method)
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
|
#destroy ⇒ Object
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
logger.warn "user #{send(Opinio.current_user_method)} 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
|
#index ⇒ Object
5
6
7
|
# File 'app/controllers/opinio/comments_controller.rb', line 5
def index
@comments = resource..page(params[:page])
end
|