Class: Opinio::CommentsController
Instance Method Summary
collapse
#reply
#custom_resource_identifier, #resource, #resource_by_params, #resource_name
Instance Method Details
#create ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# 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
messages = {:notice => I18n.translate('opinio.comment.sent', :default => "Comment sent successfully.")}
else
messages = {:error => I18n.translate('opinio.comment.error', :default => "Error sending the comment.")}
end
respond_to do |format|
format.js
format.html { redirect_to( resource, :flash => messages ) }
end
end
|
#destroy ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'app/controllers/opinio/comments_controller.rb', line 24
def destroy
@comment = Opinio.model_name.constantize.find(params[:id])
if can_destroy_opinio?(@comment)
@comment.destroy
flash[:notice] = I18n.translate('opinio.comment.destroyed', :default => "Comment removed successfully")
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( @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
|