controller.erb
def edit
@post = Post.find(params[:id])
end
def show
@post = Post.find(params[:id])
end
Schreiben Sie set_post in private
und rufen Sie es mit before_action
auf.
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