Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix guide with field_with_error proc example #8280

Merged
merged 1 commit into from Nov 20, 2012

Conversation

asanghi
Copy link
Contributor

@asanghi asanghi commented Nov 20, 2012

The "Active Record Validations and Callbacks" guide section 9.3 "Customizing the Error Messages HTML" seems to indicate that

ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
  errors = Array(instance.error_message).join(',')
  %(#{html_tag}<span class="validation-error">&nbsp;#{errors}</span>).html_safe
end

Might be a suitable option to customizing a field with error. But in the most common case this would wrap around the label as well as inputs like text_field helpers, leading to the error beings displayed twice.

The suggested fix to the guide ensures that the error is not displayed in case of labels. I'm sorry, but I just cooked up the fix in a couple of minutes so feel free if you think the solution could be better.

@rafaelfranca
Copy link
Member

Seems good. @carlosantoniodasilva WDYT?

@asanghi
Copy link
Contributor Author

asanghi commented Nov 20, 2012

Can this be backported to the current guides as well if found suitable? or would I need to send another pull request?

@rafaelfranca
Copy link
Member

We can backport

@gaurish
Copy link
Contributor

gaurish commented Nov 20, 2012

👍

@carlosantoniodasilva
Copy link
Member

Yeah, seems fine. Thanks @asanghi :)

rafaelfranca added a commit that referenced this pull request Nov 20, 2012
fix guide with field_with_error proc example
@rafaelfranca rafaelfranca merged commit f042b4e into rails:master Nov 20, 2012
rafaelfranca added a commit that referenced this pull request Nov 20, 2012
fix guide with field_with_error proc example

[ci skip]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants