Created
May 15, 2013 03:13
-
-
Save jackcallister/5581413 to your computer and use it in GitHub Desktop.
Get Bootstrap and Rails error messages to play nicely together.
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
<div class="control-group <%= control_group_error(@model, :field_name) %>"> | |
<%= f.label :field_name, :class => "control-label" %> | |
<div class="controls"> | |
<%= f.text_field :field_name %> | |
<%= error_help_text(@model, :field_name) %> | |
</div> | |
</div> |
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
# Prevent default Rails error mark up. | |
ActionView::Base.field_error_proc = Proc.new {|html, instance| html } |
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 FormHelper | |
def control_group_error(model, field_name) | |
"error" unless model.errors[field_name].blank? | |
end | |
def error_help_text(model, field_name) | |
"<span class='help-inline'>#{model.errors[field_name].join(", ")}</span>".html_safe unless model.errors[field_name].blank? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment