Created
December 3, 2009 22:06
-
-
Save dallas/248586 to your computer and use it in GitHub Desktop.
The beginnings of Flashtastic!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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