controller.erb
def edit
@post = Post.find(params[:id])
end
def show
@post = Post.find(params[:id])
end
Écrivez set_post in private
et appelez-le avec 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