Skip to content

Instantly share code, notes, and snippets.

@bellatrix988
Last active January 12, 2023 22:26
Show Gist options
  • Save bellatrix988/b21aac983d94e5fdc83ef017bad7bd9e to your computer and use it in GitHub Desktop.
Save bellatrix988/b21aac983d94e5fdc83ef017bad7bd9e to your computer and use it in GitHub Desktop.
Rails 7 & Hotwire & Turbo & Devise workaround

Rails 7 & Hotwire & Turbo & Devise workaround

This gist is relevant while this Devise issue#5446 is not closed or a better solution is not suggested.

Problem:

Not getting flashes errors using turbo.

Solutions:

1. Override FailureApp and devise parent controller.

2. Pass data: {turbo: false} along with each devise form.

an example

Since I'm using simple_form in my project, I decieded to override simple_form_form with this special options.

module SimpleFormHelper
  def devise_form_for(object, *args, &)
    form_options = { data: { turbo: false } }
    options = args.extract_options!.dup
    simple_form_for(object, *(args << options.merge(form_options)), &)
  end
 end 

And I can replace in all my devise views simple_form_for with devise_form_for. It will work just fine.

# <%= simple_form_for(resource, url: user_session_path) do |f| %>
<%= devise_form_for(resource, url: user_session_path) do |f| %>
  <%= f.input :email, required: false, autofocus: true, input_html: { autocomplete: "email" } %>
  <%= f.input :password, required: false, input_html: { autocomplete: "current-password" } %>
  <%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %>
  <%= f.button :submit %>
<% end %>

It allows simple replace it back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment