Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Consolidate flash[:some_name] messages #19
At various places in our controllers different flash notices are used. For example, there are at least
I think it would be beneficial if we could come up with a sort of standard set, which we document on the wiki as to how what to use when and how. Have a short description of each and what it does, etc.
This is especially useful for UI refactoring. Assume MarkUs will be undertaken, yet another UI redesign. The person in charge of the UI would know that the documented set has to be implemented. What's more, developers have a place to look at for controller development.
I found the following:
Perhaps the following would work instead?
They could map as such:
Any thoughts on this? With a bit of feedback, I can tackle this cleanup.
flash_message :error, 'Text to display'
Then in the templates, you'd have...
<% if flash[:success] -%> <p class="success"><%= flash[:success].join("<br />") %></p> <% end -%> <% if flash[:error] -%> <p class="error"><%= flash[:error].join("<br />") %></p> <% end -%> # etc...
That would then allow us to have multiple messages of each type.
The alternatives would be to :
B) Define each flash key (:error, :success, :notice, :warning) as an array at the beginning of a controller somehow, and that way you're always just pushing text on the array
C) Define each flash key as an array within each method that might use flash. I'd like to avoid this option, as if a dev forgets to define it as an array, the call to join from the erb will spit out a NoMethod Error. Or, to avoid this concern, we'd have to include a conditional statement in the template checking if flash[:type] is an array or a string, which isn't a very clean solution.
Forgot I never replied to this with my findings. Essentially, the idea I proposed before would only work if we differentiated between messages displayed in the headers, and left those displayed inline as being defined individually. It would clean things up a bit. I haven't been able to think of an alternative solution.
For forms flash messages, I don't know how to do that.
Could you create a PR with your modifications. I'll be happy to merge it!