Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render_flash is never called #2

Open
tkhobbes opened this issue Sep 13, 2023 · 8 comments
Open

render_flash is never called #2

tkhobbes opened this issue Sep 13, 2023 · 8 comments

Comments

@tkhobbes
Copy link

I just installed this into my little rails app but the flashes behaviour did not change.

I added a binding.pry into the render_flash helper method (right at the beginning) but it looks like this method is never called.
I have included the before_action line into my application controller. What else could be the root cause?

class ApplicationController < ActionController::Base
  include Pagy::Backend
  before_action { @pagy_locale = params[:locale] || I18n.default_locale }

  before_action :configure_permitted_parameters, if: :devise_controller?

  before_action :enable_hotflash

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
    devise_parameter_sanitizer.permit(:account_update, keys: [:name])
  end
end
@joshmn
Copy link
Owner

joshmn commented Sep 13, 2023

Everything appears to be working on my demo app. Are you able to reproduce with an example app that I could take a peak at?

@tkhobbes
Copy link
Author

I can try to create one yes. FWIW, this is the controller action (if the "else" block gets executed, no flash is displayed)

  def create
    result = Scraper::ArtistScraper.new(params[:code]).scrape
    if result.valid?
      if Artist.find_by(code: result.artist[:code]).present?
        redirect_to new_artist_scraper_path, alert: I18n.t('artist_scrapers.create.exists')
      else
        @artist_scraper = result.artist
      end
    else
      redirect_to new_artist_scraper_path, alert: result.message
    end
  end

@joshmn
Copy link
Owner

joshmn commented Sep 13, 2023

Ahhh on a redirect.

So hotflash only works with actions that render. Are you rendering a flash in your layout?

@tkhobbes
Copy link
Author

yes - application.html.erb:

  <body>
    <%= render 'shared/navbar' %>
    <section class="section m-0 p-0">
      <layout-container class="container">
        <layout-columns class="columns p-1 mb-1">
          <%= render 'shared/sidebar' if current_user %>
          <main class="column m-1 px-5 py-3 is-relative">
            <%= render 'shared/flashes' %>
            <%= yield %>
          </main>
        </layout-columns>
      </layout-container>
    </section>
    <%= render 'shared/footer' %>
  </body>

@joshmn
Copy link
Owner

joshmn commented Sep 13, 2023

Digging into this: Is the POST request a turbo request?

@tkhobbes
Copy link
Author

Yes as per the console, it's processed as TURBO_STREAM.

@joshmn
Copy link
Owner

joshmn commented Sep 18, 2023

Have you tried hitting flash.keep?

@madaarya
Copy link

madaarya commented May 4, 2024

hi @joshmn , so the redirect not support yet or any tips for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants