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