I had two fields in my form i.e start and end time fields, i am
validating times but i am not reflecting the error message at the
field, what should i have to do to diplay the error as "start time
should be before end time".
please help me

validate :valid_times

def valid_times
if start_time >= end_time
self.errors.add :start_time, 'has to be before end time'
end
end

--
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

  • Dave Aronson at Jan 26, 2012 at 8:27 pm

    On Wed, Jan 25, 2012 at 04:34, naga surya wrote:

    i am not reflecting the error message at the
    field, what should i have to do to diplay the error as "start time
    should be before end time".
    Probably your view is not checking for errors on the object. You need
    code in it something like:

    <% if @widget.errors.any? %>
    <div id="error_explanation">
    <h2><%= pluralize(@widget.errors.count, "error") %> prohibited
    this widget from being saved:</h2>
    <ul>
    <% @widget.errors.full_messages.each do |msg| %>
    <li class="error"><%= msg %></li>
    <% end %>
    </ul>
    </div>
    <% end %>

    Check your view (or layout) for such code, and if not there, stick
    this in, substituting your model name for widget.

    -Dave

    --
    Dave Aronson:  Available Cleared Ruby on Rails Freelancer
    (NoVa/DC/Remote) -- see www.DaveAronson.com, and blogs at
    www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.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.
  • Naga surya at Jan 27, 2012 at 8:10 am
    Thanks for your reply, I dont want the error to dispaly at outline, i
    want the error to display at near the date field i.e., inlne error
    display is required for me. please help me how to get it.
    Thanks in advance
    On Jan 27, 1:26 am, Dave Aronson wrote:
    On Wed, Jan 25, 2012 at 04:34, naga surya wrote:
    i am not reflecting the error message at the
    field, what should i have to do to diplay the error as "start time
    should be before end time".
    Probably your view is not checking for errors on the object.  You need
    code in it something like:

    <% if @widget.errors.any? %>
    <div id="error_explanation">
    <h2><%= pluralize(@widget.errors.count, "error") %> prohibited
    this widget from being saved:</h2>
    <ul>
    <% @widget.errors.full_messages.each do |msg| %>
    <li class="error"><%= msg %></li>
    <% end %>
    </ul>
    </div>
    <% end %>

    Check your view (or layout) for such code, and if not there, stick
    this in, substituting your model name for widget.

    -Dave

    --
    Dave Aronson:  Available Cleared Ruby on Rails Freelancer
    (NoVa/DC/Remote) -- seewww.DaveAronson.com, and blogs atwww.Codosaur.us,www.Dare2XL.com,www.RecruitingRants.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.
  • Dave Aronson at Jan 27, 2012 at 2:10 pm

    On Fri, Jan 27, 2012 at 03:10, naga surya wrote:

    Thanks for your reply, I dont want the error to dispaly at outline, i
    want the error to display at near the date field i.e., inlne error
    display is required for me. please help me how to get it.
    Oh! Okay. That's a bit more tedious code. What you can do then is
    have the errors attach to the specific fields, and check for them when
    displaying each field. I think there are some standard ways to do
    this, but I don't recall offhand where to find examples and
    instructions. Google is your friend. IIRC, the default stuff will at
    least put a red box around the specific fields, using CSS....

    -Dave

    --
    Dave Aronson:  Available Cleared Ruby on Rails Freelancer
    (NoVa/DC/Remote) -- see www.DaveAronson.com, and blogs at
    www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJan 26, '12 at 11:52a
activeJan 27, '12 at 2:10p
posts4
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Dave Aronson: 2 posts Naga surya: 2 posts

People

Translate

site design / logo © 2021 Grokbase