I have a list of symbols that correspond to various flash messages:
:is_self
:already_exist
:already_added
:invited
:added
Every time I run my method, variable answer
is assigned one of these symbols. I assigned to variable message
the flash message I want to display:
message = t("flash.#{answer.to_s}")
This works fine. At the end of my method, I have something like:
respond_to do |format|
format.html { redirect_to url, flash: { info: message } }
end
I would like to change the flash message color (switch between info: success: error:
). How can I set a hash variable that would contain the right color for the flash message? I tried something like:
new_hash = { :is_self => "info:" , :already_exist => "info:" , :already_added => "info:", :invited => "success:", :added => "success:", }
flash_color = new_hash[answer]
And then:
respond_to do |format|
format.html { redirect_to url, flash: { flash_color message } }
end
But I won't work. I have no idea how to give the right syntax.