From b8916463760bd52c26da1b4cd24961a923f87597 Mon Sep 17 00:00:00 2001 From: TomaszKot11 Date: Sun, 30 May 2021 10:04:39 +0200 Subject: [PATCH] Dodanie akcji kontrolera --- app/controllers/posts_controller.rb | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 app/controllers/posts_controller.rb diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb new file mode 100644 index 0000000..1dc66f5 --- /dev/null +++ b/app/controllers/posts_controller.rb @@ -0,0 +1,48 @@ +class PostsController < ApplicationController + + def index + @posts = Post.all + end + + def show + @post = Post.find(params[:id]) + end + + def new + @post = Post.new + end + + def create + @post = Post.new(post_params) + if @post.save + redirect_to posts_path + else + render :new + end + end + + def edit + @post = Post.find(params[:id]) + end + + def update + @post = Post.find(params[:id]) + if @post.update(post_params) + redirect_to posts_path + else + render :edit + end + end + + def destroy + @post = Post.find(params[:id]) + @post.destroy + redirect_to posts_path + end + + private + + def post_params + params.require(:post).permit(:content) + end +end \ No newline at end of file