Thanks for your advice but I have tried that but it doesn''t work. Let
me clarify what I have in view file
<label for=''join_date''>Join Date:</label>
<%=date_select :job_experience, :join_date,
:start_year=>Time.now.year, :end_year=>1900,
:order=>[:month,:year],:discard_type=>true,:day=>false,
:include_blank=>true
%>
<label for=''left_date''>Left Date:</label>
<%=date_select :job_experience, :left_date,
:start_year=>Time.now.year, :end_year=>1900,
:order=>[:month,:year],:discard_type=>true,
:day=>false,:include_blank=>true
%>
Then I write the following in my model
def validate
errors.add_to_base("left date cannot be less than join date ") if
left_date<join_date
end
But the validation doesn''t work. Please Rails Lover give me some
suggestion.
On May 22, 6:58 pm, Wayne Molina
<wayne.mol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Only way I know how to do this is to add your own validate method e.g.:
>
> # in your model...
> def validate
> errors.add(:start_date, "must be less than the end date") if
> start_date >= end_date
> end
>
> There might be a helper to do this, but at the time I wasn''t aware
of
> one so this is how I did it ;-)
>
> Hope this helps.
>
> - Wayne
>
> On May 22, 2008, at 3:09 AM, mrbless wrote:
>
>
>
> > I have to fields in database start_date and end_date. What I want to
> > validate is that start_date must be less than end_date. I want the
> > model level validation . Please help me.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---