railsのコントローラで、createやupdateアクションではよく
def create hoge = Hoge.new(hoge_params) #hoge_paramsがprivateで定義されている if hoge.save(もしくはupdate) redirect_to root_path, notice: '保存に成功しました。' else render :new, alert: '保存に失敗しました。' end
みたいに例外処理をしますが、destroyアクションだと単純に
def destroy hoge = Hoge.find(params[:id]) hoge.destroy redirect_to root_path, notice: '削除に成功しました。' end
という記述を見ます。
destroyアクションだと、なぜ例外処理が必要無いのでしょうか?
単純に、「削除できない場合が無い」というのが理由なのでしょうか?
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。