This project is archived and is in readonly mode.
[PATCH] error_messages_on returning content for methods without errors
Reported by Geoff Garside | February 24th, 2010 @ 06:31 PM
When using error_messages_on
in a form, a
<div class="formErrors"></div>
element is
being rendered into the form for methods without any errors on
them.
Given the form
<% form_for @object do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.error_messages_on :name %>
<% end %>
I'm getting this HTML
<form action="/accounts" class="new_account" id="new_account" method="post"><div style="margin:0;padding:0;display:inline"><input name="authenticity_token" type="hidden" value="BOt7Iq1ZyBtEYyqbb0DTAj2tNJPYudQA3VmXesekztI=" /></div>
<label for="account_name">Name</label>
<input id="account_name" name="account[name]" size="30" type="text" />
<div class="formError"></div>
</form>
I think this might be related to errors[:name]
returning an empty array instead of nil
as it used
to
Loading development environment (Rails 3.0.0.beta1)
>> Account.new.errors[:name]
=> []
I've attached a patch which replicates this, I'm not sure how it
should be fixed though. Either ActiveModel::Errors#[]
needs to be patched to return nil
for methods without
errors or else the
ActionView::Helpers::ActiveModelHelper#error_messages_on
needs to be changed to check that the errors on the method are not
empty.
Comments and changes to this ticket
-
Geoff Garside February 24th, 2010 @ 06:41 PM
Working on the idea of trying to break the rest of AMo and AP::AV the least I changed
ActionView::Helpers::ActiveModelHelper#error_messages_on
and it was very simple. Love it when that happens.Patch is attached.
-
Geoff Garside February 24th, 2010 @ 06:44 PM
Additionally now pushed these up to a branch on my fork incase thats easier to apply via
-
Geoff Garside February 24th, 2010 @ 11:09 PM
- Tag changed from actionview, errors to actionview, errors, patch
- Title changed from error_messages_on returning content for methods without errors to [PATCH] error_messages_on returning content for methods without errors
-
Geoff Garside February 26th, 2010 @ 09:00 AM
Sorry just read the contributor guidelines. Attached single file patch with both the test and fix patches integrated.
-
Geoff Garside March 27th, 2010 @ 09:59 AM
- Tag changed from actionview, errors, patch to actionview, errors, patch, rails3
-
Repository March 27th, 2010 @ 10:10 AM
- State changed from new to resolved
(from [0a352056a4055c170e62a521267f5bc51c6659a0]) Fixes a bug where error_messages_for was returning an empty div [#4048 state:resolved] (ht: Geoff Garside) http://github.com/rails/rails/commit/0a352056a4055c170e62a521267f5b...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 4048 [PATCH] error_messages_on returning content for methods without errors (from [0a352056a4055c170e62a521267f5bc51c6659a0]) Fixes a...