controller.erb
def edit
@post = Post.find(params[:id])
end
def show
@post = Post.find(params[:id])
end
Write set_post in private
and call it with before_action
.
controller.erb
before_action :set_post, only: [:edit, :show]
def edit
end
def show
end
private
def set_post
@post = Post.find(params[:id])
end
Recommended Posts