Table: RailsNotes
User: dreamable
Created at: 2023-02-27 09:05:57 UTC
Updated at: 2023-02-27 09:07:36 UTC
Reference:(Table ID 3, Record ID 51)

标题 :
Rails Turbo & "responses must redirect to another location"
笔记 :

When I started a new project in Rails 7 and copy code from previous project, I encountered the several problems. For example, for login page, if password is wrong, the page doesn't show errors. For signup, similarly, it doesn't show any error messages.

I found JS console error

responses must redirect to another location

Then I found the articles 1 & 2

Here is why:

  • In Rails 7, Turbo replaced Turbolinks.
  • Turbo requires each response must redirect to another location.
    format.html { render :signup } # same page 
    format.html { flash[:error] = "ERROR" } # same page, no redirect
  • There are two solutions:

    • same page, but different status
    format.html { render :signup, status: :unprocessable_entity}
    format.html { flash[:error] = "ERROR"; redirect_to({action: :login})} # redirect to itself. 
    
    • use turbo_frame_tag
Tag: