i have a shared template that i use regularly to show errors like :
<%= render "shared/flash_error", :error => flash[:error], :info => flash[:info] %>
This variables are optional, so my view is like :
<% if defined?(error) and error %>
<div class="error">
<%= error %>
</div>
<% end %>
<% if defined?(info) and info %>
<div class="info">
<%= info %>
</div>
<% end %>
Now, there are cases when i would need to add a new optional variable and extend the partial with other types of errors. This, however, can make the rendering hard to keep up with. I would now need to edit every render and change it to :
<%= render "shared/flash_error", :error => flash[:error], :info => flash[:info], :new_entry => flash[:new_entry] %>
and so on with every new entry. So, i am wondering, is there a way for the rendered partial to ‘observe’ specific flash variables,so that i don’t even have to pass them as attributes to the rendered view ?
Yeap, tried it and works fine. Something like :
where msg_notifications is just a hash filled with everything, so it can be changed in a DRY way. Simple, yet sometimes the mind plays bad games 😛