+
+
+
-
+ 2
+
+
+
+
+
+
+
class WikiCommentsController < ApplicationController
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
before_action :set_comment, only: [:show, :edit, :update, :destroy]
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
before_action :set_entry, only:[:index, :new, :create]
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
# GET /comments
+
+
+
+
+
-
+
+
+
+
+
+
+
+
# GET /comments.json
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
def index
+
+
+
+
+
-
+
+
+
+
+
+
+
+
#Método que recupera um array com todos os comentários
+
+
+
+
+
-
+ 1
+
+
+
+
+
+
+
@comments = WikiComment.all
+
+
+
+
+
-
+
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
# GET /comments/1
+
+
+
+
+
-
+
+
+
+
+
+
+
+
# GET /comments/1.json
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
def show
+
+
+
+
+
-
+
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
# GET /comments/new
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
def new
+
+
+
+
+
-
+ 3
+
+
+
+
+
+
+
@comment = WikiComment.new
+
+
+
+
+
-
+
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
# GET /comments/1/edit
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
def edit
+
+
+
+
+
-
+
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
# POST /comments
+
+
+
+
+
-
+
+
+
+
+
+
+
+
# POST /comments.json
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
def create
+
+
+
+
+
-
+
+
+
+
+
+
+
+
#Método para a criação do comentário que faz a ligação da existencia desse comentário com uma Wikientry já criada, pois sem isso o comentário não pode existir
+
+
+
+
+
-
+ 5
+
+
+
+
+
+
+
@comment = WikiComment.new(comment_params.merge({entry: @entry}))
+
+
+
+
+
-
+
+
+
+
+
+
+
+
#verifica se o comentario pode ser salvo e se sim renderiza a página da entry a qual o comentário pertence, caso contrário, retorna um erro
+
+
+
+
+
-
+ 5
+
+
+
+
+
+
+
respond_to do |format|
+
+
+
+
+
-
+ 5
+
+
+
+
+
+ then: 3
+
+
+
+
+
if @comment.save
+
+
+
+
+
-
+ 6
+
+
+
+
+
+
+
format.html { redirect_to @comment.entry, notice: 'Comentário foi criado com sucesso.' }
+
+
+
+
+
-
+ 3
+
+
+
+
+
+
+
format.json { render :show, status: :created, location: @comment }
+
+
+
+
+
-
+
+
+
+
+
+
+ else: 2
+
+
+
+
+
else
+
+
+
+
+
-
+ 4
+
+
+
+
+
+
+
format.html { render :new }
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
format.json { render json: @comment.errors, status: :unprocessable_entity }
+
+
+
+
+
-
+
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
# PATCH/PUT /comments/1
+
+
+
+
+
-
+
+
+
+
+
+
+
+
# PATCH/PUT /comments/1.json
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
def update
+
+
+
+
+
-
+
+
+
+
+
+
+
+
#Método que permite a atualização de um comentário. Esse método não está sendo utilizado no momento.
+
+
+
+
+
-
+ 3
+
+
+
+
+
+
+
respond_to do |format|
+
+
+
+
+
-
+ 3
+
+
+
+
+
+ then: 2
+
+
+
+
+
if @comment.update(comment_params)
+
+
+
+
+
-
+ 4
+
+
+
+
+
+
+
format.html { redirect_to @comment.entry, notice: 'Comentário foi editado com sucesso.' }
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
format.json { render :show, status: :ok, location: @comment.entry }
+
+
+
+
+
-
+
+
+
+
+
+
+ else: 1
+
+
+
+
+
else
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
format.html { render :edit }
+
+
+
+
+
-
+ 1
+
+
+
+
+
+
+
format.json { render json: @comment.errors, status: :unprocessable_entity }
+
+
+
+
+
-
+
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
# DELETE /comments/1
+
+
+
+
+
-
+
+
+
+
+
+
+
+
# DELETE /comments/1.json
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
def destroy
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
@comment.destroy
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
respond_to do |format|
+
+
+
+
+
-
+ 4
+
+
+
+
+
+
+
format.html { redirect_to @comment.entry, notice: 'Comentário foi excluído com sucesso.' }
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
format.json { head :no_content }
+
+
+
+
+
-
+
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
private
+
+
+
+
+
-
+
+
+
+
+
+
+
+
# Use callbacks to share common setup or constraints between actions.
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
def set_comment
+
+
+
+
+
-
+
+
+
+
+
+
+
+
#Método para localizar o comentário com a id específica
+
+
+
+
+
-
+ 7
+
+
+
+
+
+
+
@comment = WikiComment.find(params[:id])
+
+
+
+
+
-
+
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
def set_entry
+
+
+
+
+
-
+
+
+
+
+
+
+
+
#método para localizar a WikiEntry a qual o comentário pertence e ele é chamado antes das ações index, new e create dos comentários para que seja possível recupera-los ou setá-los em relação as devidas WikiEntries
+
+
+
+
+
-
+ 9
+
+
+
+
+
+
+
@entry = WikiEntry.find(params[:wiki_entry_id])
+
+
+
+
+
-
+
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
# Never trust parameters from the scary internet, only allow the white list through.
+
+
+
+
+
-
+ 2
+
+
+
+
+
+
+
def comment_params
+
+
+
+
+
-
+
+
+
+
+
+
+
+
#Parametros permitidos a um comentário
+
+
+
+
+
-
+ 8
+
+
+
+
+
+
+
params.require(:wiki_comment).permit(:content)
+
+
+
+
+
-
+
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
end
+
+
+
+
+
Comentário #<%=comment.id%>
+<%=comment.content%>
+