highway/site/app/controllers/posts_controller.rb
2025-04-26 22:01:15 -04:00

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