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

Flash not showing after redirect with Turbolinks #54

Open
matissg opened this issue Sep 14, 2019 · 1 comment
Open

Flash not showing after redirect with Turbolinks #54

matissg opened this issue Sep 14, 2019 · 1 comment

Comments

@matissg
Copy link

matissg commented Sep 14, 2019

In my update action I have

respond_to do |format|
  if @offer.update(offer_params)
    flash[:success] = "#{@offer.name} #{t(:updated)}"
    format.js
  else
    format.js {render :edit}
  end
end

Then in update.js.erb redirect is done with:
Turbolinks.visit("<%= seller_offers_path %>");

In application.js there is

$(document).on('turbolinks:load', UnobtrusiveFlash.showFlashFromCookies, function() {
  //something...
});

As in this suggestion in session_store.rb I've set:
Rails.application.config.session_store :cookie_store, key: 'myapp', expire_after: 1.day, httponly: { except: ['flash'] }

At the moment redirect after update is done, however no flash. If I remove Turbolinks.visit("<%= seller_offers_path %>"); then flash is shown, but I stay in same page as there is no redirect.

Is there a way to have flash on next page after redirect with Turbolinks, please?

My tech stack: Rails 6, unobtrusive_flash 3.3.1, Ruby 2.6.3

@fffx
Copy link

fffx commented Feb 20, 2021

This may be caused by turbo/turbolink replaced current page on flash show, this is the process:

request -> redirect with flash message -> show flash message but turbo/turbolink will replace current page immediately, so you wouldn't notice it.

You can find out this by remove UnobtrusiveFlash.showFlashFromCookies callback, and call UnobtrusiveFlash.showFlashFromCookies in chrome console after redirect.

You may solve this by show flash message after turbo/turbolink render

  $(document).on('turbo:render', function(){
    UnobtrusiveFlash.showFlashFromCookies()
  })

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

2 participants