HI i am using the following to display the from validation errors
inline in the views, as suggested in the rails guide.http://
guides.rubyonrails.org/active_record_validations_callbacks.html

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

It's working, but displaying the same error message twice, one before
the input field and one after the input field. Can't figure out...

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Tim Shaffer at Jan 11, 2012 at 2:58 pm
    What does your view look like? Do you have any error message related code
    in there?

    What does the output HTML look like? Is the error message repeated in the
    HTML?

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/r0yUhc36mksJ.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Venkata reddy at Jan 12, 2012 at 7:33 am
    say for instance,
                            i have a validation on
    validates first_name, :presence => true


                                                 ----------------------
    First Name: can't be blank | | can't be
    blank
                                                 ----------------------

    :) so like above, the error message coming twice beside the input
    field, if the validation fails.
    On Jan 11, 7:58 pm, Tim Shaffer wrote:
    What does your view look like? Do you have any error message related code
    in there?

    What does the output HTML look like? Is the error message repeated in the
    HTML?
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Venkata reddy at Jan 18, 2012 at 9:37 am
    I found that the validation error is coming for f.label as well.
    Why is this happening? if i remove f.label and put not text without
    using label tag, it is only coming once for text input.

    Anybody there...
    On Jan 12, 12:33 pm, venkata reddy wrote:
    say for instance,
    i have avalidationon
    validates first_name, :presence => true

    ----------------------
    First Name:   can't be blank   |                      |   can't be
    blank
    ----------------------

    :) so like above, theerrormessage coming twice beside the input
    field, if thevalidationfails.

    On Jan 11, 7:58 pm, Tim Shaffer wrote:






    What does your view look like? Do you have anyerrormessage related code
    in there?
    What does the output HTML look like? Is theerrormessage repeated in the
    HTML?
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Andrew Drummond at Feb 26, 2012 at 8:16 pm

    venkata reddy wrote in post #1041460:
    I found that the validation error is coming for f.label as well.
    Why is this happening? if i remove f.label and put not text without
    using label tag, it is only coming once for text input.

    Anybody there...
    I'm having the same exact issue as well so if anyone could help us out
    that would be great! I spent the morning trouble shooting this issue and
    had zero luck.

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Chandresh Pant at Sep 2, 2014 at 12:12 am
    I know its an old post, but if anyone is facing this issue now, you can
    check if the html_tag is not label, using something like:

    html_tag !~ /label/

    Also, I would recommend using simple_form which comes with inline error
    messages.

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/634ab0d41dcce8ba46b40c6227e7d899%40ruby-forum.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJan 11, '12 at 7:13a
activeSep 2, '14 at 12:12a
posts6
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase