thank_you
thank_you

Reputation: 11107

Flash and redirect_to in one line not producing flash

I have the following code

redirect_to questionnaire_url, error: "Now please fill in the questionnaire."

Normally if I set a flash[:notice] value above the redirect the flash shows on my page, however when I use the code above it doesn't.

My code to display the flash is

- flash.each do |key, value|
  = content_tag(:div, value, class: "alert alert-#{key}")

After writing in = flash.inspect I received

#<ActionDispatch::Flash::FlashHash:0x000000044322f0 @used=#<Set: {}>, @closed=false, @flashes={}, @now=nil>

This is of course written using SLIM template language. My question is what is notice actually producing and how can I adjust my code to fix it? Thanks.

Upvotes: 3

Views: 1935

Answers (2)

sloneorzeszki
sloneorzeszki

Reputation: 1524

Add in your ApplicationController:

add_flash_types :error

Upvotes: 0

PinnyM
PinnyM

Reputation: 35531

The reason is because only alert and notice can be used inline with redirect_to using this syntax. For any other flash key, you need to specify:

redirect_to questionnaire_url, flash: {error: "Now please fill in the questionnaire."}

Upvotes: 7

Related Questions