Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The beginnings of Flashtastic!
# Create a ViewHelper class or module (whatever) for dealing with flash messages in an easy-to-use format
# the current way:
<%- if flash[:error] -%>
<p class="error"><%= flash[:error] %></p>
<%- end -%>
<%- if flash[:notice] -%>
<p class="notice success">
<%= flash[:notice] %> <%= link_to('View Now', view_post_path) if post_created %>
</p>
<%- end -%>
# which can be somewhat simplified to:
<%= content_tag(:p, flash[:error], :class => 'error') if flash[:error] %>
<%= content_tag(:p, "#{flash[:notice]}#{link_to('View Now', view_post_path) if post_created}", :class => 'notice success') if flash[:notice] %>
# but why not…
<%= FlashMessage.error.as_p %>
# and even…
<%= FlashMessage.notice.as_p.with_class(:success).append_text_if(post_created, link_to('View Now', view_post_path)) %>
# or even…
<%- FlashMessage.notice.as_p(:class => 'success') do |fm| -%>
<%= fm %> <%= link_to('View Now', view_post_path) if post_created %>
<%- end -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.