/
LizaLev
/
AcademyHomework
Обзор
Документация
Войти
/
LizaLev
/
AcademyHomework
Код
Запросы
3
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
course_project
CourseProject/app/controllers/posts_controller.rb
50 строк
977 B
EarllGrayy
Добавить выполнение курсового проекта
18 окт 2024, 14:05
18 окт 2024, 14:05
3e01177
Код
Авторство
О чём код?
class PostsController < ApplicationController before_action :authenticate_user! def new @post = Post.new end def create @post = current_user.posts.build(post_params) if @post.save redirect_to root_path, notice: "Post created successfully" else render :new end end def show @post = Post.find(params[:id]) @comments = @post.comments.order(created_at: :desc) @comment = Comment.new end def destroy @post = Post.find(params[:id]) if @post.user == current_user @post.destroy redirect_to root_path, notice: "Post was successfully deleted." end end def edit @post = Post.find(params[:id]) end def update @post = Post.find(params[:id]) if @post.update(post_params) redirect_to root_path, notice: "Post was successfully updated." else render :edit end end private def post_params params.require(:post).permit(:image, :description) end end