Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5] Dodanie kontrolera #5

Open
wants to merge 1 commit into
base: Dodanie-routingu
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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