LoginSignup
0
0

More than 3 years have passed since last update.

【Error】編集後に画面遷移しない事象の解消法

Posted at

概要

タスクの編集画面を実装し、確認のため編集を行い、ボタンを押下したのですが画面が変わらず。。。。:confounded:

結果としては、「redirect_to」していなかった:sweat_smile:ということでしたが、エラー解決するまでの経緯を備忘録として残します!

確認方法

【前提】
編集画面で登録ボタンを押した後は、ボタンは押下できない状況にあった。
画面遷移もされない。
①MySQLに編集データが保存されているかを確認

変更されている:ok_hand:

②エラー画面が出ていないのであれば、ターミナルにエラー情報が記入されているのではないかを確認

terminal
No template found for TasksController#update, rendering head :no_content
Completed 204 No Content in 139ms (ActiveRecord: 3.4ms)

あった:rolling_eyes:
No templateって記載されてた!!

③コントローラーを確認
→redirect_toが記載なし:scream:

修正箇所

修正前

tasks_controller.rb
def update
  @task.update(task_params)
  if @task.valid?
    @task.save
  else
    flash.now[:alert] = 'タスク名を入力してください'
    render :index
  end
end

修正後

tasks_controller.rb
def update
  @task.update(task_params)
  if @task.valid?
    @task.save
    redirect_to group_tasks_path(@group), notice: 'タスクが変更されました'
  else
    flash.now[:alert] = 'タスク名を入力してください'
    render :index
  end
end

皆さま、お気をつけください:bow_tone1:

参考

エラー204に関するURLです。
https://developer.mozilla.org/ja/docs/Web/HTTP/Status/204

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