0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ifって大事

Posted at

Chat_appというアプリのテキストにて

app/controllers/rooms_controller.rb
  def destroy
    room = Room.find(params[:id])
    room.destroy
    redirect_to root_path
  end

###削除に失敗してもルートパスに飛ばされる

furimaというアプリテキストにて

app/controllers/items_controller.rb
  def destroy
    if @item.destroy
      redirect_to root_path
    end
  end

削除に成功すればルートパスに飛ばされる。
削除に失敗したときは同じ画面のまま

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?