-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from TreinaDev/feat/responder-comentrio
Feat/responder comentário
- Loading branch information
Showing
23 changed files
with
376 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Replies | ||
class LikesController < LikesController | ||
before_action :set_likeable | ||
|
||
private | ||
|
||
def set_likeable | ||
@likeable = Reply.find(params[:reply_id]) | ||
@post = @likeable.comment.post | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class RepliesController < ApplicationController | ||
before_action :authenticate_user! | ||
def create | ||
comment = Comment.find(params[:comment_id]) | ||
@reply = comment.replies.build(reply_params) | ||
|
||
if @reply.save | ||
redirect_to post_path(comment.post), notice: t('.success') | ||
else | ||
redirect_to post_path(comment.post), alert: t('.error') | ||
end | ||
end | ||
|
||
private | ||
|
||
def reply_params | ||
reply_params = params.require(:reply).permit(:message) | ||
reply_params[:user_id] = current_user.id | ||
reply_params | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Reply < ApplicationRecord | ||
belongs_to :user | ||
belongs_to :comment | ||
has_many :likes, as: :likeable, dependent: :destroy | ||
validates :message, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
pt-BR: | ||
activerecord: | ||
models: | ||
reply: | ||
one: Resposta | ||
other: Respostas | ||
attributes: | ||
reply: | ||
message: 'Resposta' | ||
replies: | ||
send: 'Enviar Resposta' | ||
create: | ||
success: 'Resposta enviada com sucesso!' | ||
error: 'Não foi possível enviar sua resposta' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateReplies < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :replies do |t| | ||
t.references :user, null: false, foreign_key: true | ||
t.references :comment, null: false, foreign_key: true | ||
t.text :message | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Oops, something went wrong.