Created
September 2, 2010 10:08
-
-
Save nu7hatch/562117 to your computer and use it in GitHub Desktop.
Flash messages and form errors in good way
This file contains hidden or 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
- if flash.keys.size > 0 | |
.flash-messages | |
- flash.each do |type, message| | |
%div(class="flash-message flash-#{type}")= message |
This file contains hidden or 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
- if object.errors.any? | |
.error-explanation | |
%h3=t ".#{object.class.to_s.underscore}.header", :default => t(".header") | |
%ul | |
- object.errors.full_messages.each do |msg| | |
%li= msg |
This file contains hidden or 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
module ApplicationHelper | |
# It displays flash messages. | |
def flash_messages | |
render :partial => "shared/flash_message" | |
end | |
# It displays validation errors for given object. Here is the HAML example: | |
# | |
# - form_for @user do |f| | |
# = form_errors(f) | |
# -# ... | |
# | |
# - form_for "/sessions/login" do |f| | |
# = form_errors(@session) | |
# -# ... | |
def form_errors(object) | |
object = object.object if object.respond_to? :object | |
# I've used locals here because object params doesn't work properly. | |
render :partial => "shared/form_errors", :locals => { :object => object } | |
end | |
# ... | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment