/
LizaLev
/
AcademyHomework
Обзор
Документация
Войти
/
LizaLev
/
AcademyHomework
Код
Запросы
3
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
course_project
CourseProject/app/controllers/comments_controller.rb
29 строк
745 B
EarllGrayy
Добавить выполнение курсового проекта
18 окт 2024, 14:05
18 окт 2024, 14:05
3e01177
Код
Авторство
О чём код?
class CommentsController < ApplicationController before_action :authenticate_user! def create @post = Post.find(params[:post_id]) @comment = @post.comments.build(comment_params) @comment.user = current_user if @comment.save redirect_to post_path(@post), notice: "Comment was successfully added." else redirect_to post_path(@post), alert: "There was an error adding your comment." end end def destroy @comment = Comment.find(params[:id]) if @comment.user == current_user @comment.destroy redirect_back fallback_location: root_path, notice: "Comment was successfully deleted." end end private def comment_params params.require(:comment).permit(:content) end end