Skip to content

Instantly share code, notes, and snippets.

@dallas
Created December 3, 2009 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dallas/248586 to your computer and use it in GitHub Desktop.
Save dallas/248586 to your computer and use it in GitHub Desktop.
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