Tuesday, 9 October 2012

rails custom errors

<% if @entry.errors.include?(:state) %>
<div class="control-group">
<div class="controls">
<div class="error"> <%= @entry.errors["state"][0] %></div>
</div>
</div>
<% end %>
###############OR
#in application rb
Include the errors in the html fields
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
"<div class=\"field_with_errors\">
#{html_tag}
<div class=\"error\">#{instance.error_message.first}</div>
</div>".html_safe
end
view raw gistfile1.erb hosted with ❤ by GitHub

No comments:

Post a Comment