Hi!
Lets say I access the exposed flash from a template:
- unless flash[:success_messages].nil?
- flash[:success_messages].each do |success_message|
.alert.alert-success role="alert"
= success_message
- unless flash[:info_messages].nil?
- flash[:info_messages].each do |info_message|
.alert.alert-info role="alert"
= info_message
- unless flash[:warning_messages].nil?
- flash[:warning_messages].each do |warning_message|
.alert.alert-warning role="alert"
= warning_message
- unless flash[:error_messages].nil?
- flash[:error_messages].each do |error_message|
.alert.alert-danger role="alert"
= error_message
Now, I would like to refactor that template to something like
- success_flash_messages.each do |success_message|
.alert.alert-success role="alert"
= success_message
- info_flash_messages.each do |info_message|
.alert.alert-info role="alert"
= info_message
- warning_flash_messages.each do |warning_message|
.alert.alert-warning role="alert"
= warning_message
- error_flash_messages.each do |error_message|
.alert.alert-danger role="alert"
= error_message
For that I want to create a Web::Helper::FlashMessages.
Now the question: is there a way I can expose the flash method to the Helper as well? Or the right way of doing something like that is something like:
- success_messages_from(flash).each do |success_message|
.alert.alert-success role="alert"
= success_message
- info_messages_from(flash).each do |info_message|
.alert.alert-info role="alert"
= info_message
- warnings_messages_from(flash).each do |warning_message|
.alert.alert-warning role="alert"
= warning_message
- error_messages_from(flash).each do |error_message|
.alert.alert-danger role="alert"
= error_message
So, as a more general question: can exposures be exposed to Views and Helpers as well? Or would that be a bad practice?
Thanks!
Martin