Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Adding a helper to render all messages stored on flash object. #3009
I've added a helper to render all flash messages and customize the output if needed.
class PostsController < ApplicationController def index flash[:notice] = "Everything is ok :)" flash[:alert] = "Error :(" end end
Then on the view:
@dmathieu I've considered to use simpler keys like :class and :element (or :tag, as you suggested), but I've chose a more fluent interface basicaly because of two reasons:
But of course, I can change the interface if most people prefer keys like :class and :tag.
@dmathieu I agree with you that this helper don't have a interface consistent with other helpers. But as I see, it can't be completely consistent.
Most helpers render one HTML element, so they offer an argument to set the attributes/values of this HTML element (html_options hash argument). But on this case, the helper renders multiple HTML elements. Though html_options could be used anyway, even we're setting the attributes/values of more than one HTML element, we still need to set the parent element of each flash message. So, we would include on this hash a :tag/:element/:parent_element key, breaking the consistency of html_options, which usually only setts attributes/values, but now is setting attributes/values and the parent element.
But again, I can change the interface without problems, also because you have a definitely valid point. I just need a guideline from someone from the core team of which approach to follow, assuming they agree with this helper.
This comment has been minimized.
This comment has been minimized.Show comment Hide comment
Thanks but this has the same problem as