You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.2 KiB
59 lines
1.2 KiB
class PostsController < ApplicationController
|
|
before_action :set_post, only: %i[show edit update destroy]
|
|
|
|
# GET /posts
|
|
def index
|
|
@posts = Post.all
|
|
end
|
|
|
|
# GET /posts/1
|
|
def show
|
|
end
|
|
|
|
# GET /posts/new
|
|
def new
|
|
@post = Post.new
|
|
end
|
|
|
|
# GET /posts/1/edit
|
|
def edit
|
|
end
|
|
|
|
# POST /posts
|
|
def create
|
|
@post = Post.new(post_params)
|
|
|
|
if @post.save
|
|
redirect_to @post, notice: 'Post was successfully created.'
|
|
else
|
|
render :new, status: :unprocessable_content
|
|
end
|
|
end
|
|
|
|
# PATCH/PUT /posts/1
|
|
def update
|
|
if @post.update(post_params)
|
|
redirect_to @post, notice: 'Post was successfully updated.', status: :see_other
|
|
else
|
|
render :edit, status: :unprocessable_content
|
|
end
|
|
end
|
|
|
|
# DELETE /posts/1
|
|
def destroy
|
|
@post.destroy!
|
|
redirect_to posts_path, notice: 'Post was successfully destroyed.', status: :see_other
|
|
end
|
|
|
|
private
|
|
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
def set_post
|
|
@post = Post.find(params.expect(:id))
|
|
end
|
|
|
|
# Only allow a list of trusted parameters through.
|
|
def post_params
|
|
params.require(:post).permit(:title, :quantity, :content)
|
|
end
|
|
end
|