Skip to content

Commit

Permalink
Dodanie akcji kontrolera
Browse files Browse the repository at this point in the history
  • Loading branch information
TomaszKot11 committed May 30, 2021
1 parent 09b8ba6 commit b891646
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b891646

Please sign in to comment.