mirror of
https://github.com/System-End/highway.git
synced 2026-04-20 00:25:16 +00:00
46 lines
710 B
Ruby
46 lines
710 B
Ruby
class PostsController < ApplicationController
|
|
|
|
before_action :set_post, only: %i[ show edit update ]
|
|
|
|
def index
|
|
@posts = Post.all
|
|
end
|
|
|
|
def show
|
|
end
|
|
|
|
def new
|
|
@post = Post.new
|
|
end
|
|
|
|
def create
|
|
@post = Post.new(post_params)
|
|
if @post.save
|
|
redirect_to @post
|
|
else
|
|
render :new, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def edit
|
|
end
|
|
|
|
def update
|
|
if @post.update(post_params)
|
|
redirect_to @post
|
|
else
|
|
render :edit, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def set_post
|
|
@post = Post.find(params[:id])
|
|
end
|
|
|
|
def post_params
|
|
params.expect(post: [ :name, :description, :featured_image, :hours ])
|
|
end
|
|
|
|
end
|