Validtion for non active record classes

Hi

  Can I use the active record validation for non active record

classes.
I have a class

class ServiceDeskResolutionEffort
attr_reader :days
attr_reader :hours
attr_reader :minutes

def initialize(data)
@passed_effort= data.split(’:’).collect! {|n| n}
@days = @passed_effort[0]
@hours = @passed_effort[1]
@minutes = @passed_effort[2]
end

end

In the view

In controller
#for exampleday:hour:min
@sd_resol = ServiceDeskResolutionEffort.new(“1:22:10”)

Here HOW CAN I IMPLEMENT VALIDATION THAT HOUR NOT GREATER THAN 23 AND
MINUTE NOT GREATER HAN 59 AND ALSO CHECK NON NUMERIC CHARACTERS NOT TO
BE ENTERED ALL THESE DAY:HOUR:MINUTE

Sijo

Day: <%= text_field :sd_resol, "days", "size" => 2 %> Hr: <%= text_field :sd_resol, "hours", "size" => 2 %> Min: <%= text_field :sd_resol, "minutes", "size" => 2 %>

Sorry sir A change is there i need the vallidation when i save …My
controller as

def sd_resolution_save
@sd_effort=params[:sd_resol][:days]+’:’+params[:sd_resol][:hours]+’:’+params[:sd_resol][:minutes]
@sd_resolution_id=params[:sd_resolution_id]
if @sd_resolution_id==nil
@service_desk_resolution=ServiceDeskResolution.new(params[:sd_resolution])
@service_desk_resolution.effort=@sd_effort
@service_desk_resolution.save
else
@sd_ticket_resolution=ServiceDeskResolution.find @sd_resolution_id
@sd_ticket_resolution.update_attribute(:effort,@sd_effort)
@update_sd_ticket_resolution=@sd_ticket_resolution.update_attributes(params[:sd_resolution])
end
redirect_to :action => ‘show_details’, :id => params[:id]
end

HERE BEFORE SAVING @service_desk_resolution.effort I NEED
VALIDATION…ALL THE OTHER SAME AS MY PROBLEM…AND PLEASE TELL ME HOW TO
CAPTURE THAT ERROR(IF EXISTS ALSO…Here ServiceDeskResolution is an
active record class

Sijo

Hey,
Please find the code as follows.

class ServiceDeskResolutionEffort
attr_reader :seconds
attr_reader :hours
attr_reader :minutes

def initialize(data)
begin
@passed_effort= data.split(‘:’).collect! {|n| n}
hours = @passed_effort[0]
minutes = @passed_effort[1]
seconds = @passed_effort[2]
if /^(\d)(\d?)$/.match(hours) == nil || /^(\d)(\d)$/.match(minutes)

nil || /^(\d)(\d)$/.match(seconds) == nil
raise “Please enter the numeric value in time.”
elsif hours.to_i > 23 || minutes.to_i > 59 || seconds.to_i > 59
raise “Please enter the right rage of values.”
else
@hours = hours
@minutes = minutes
@seconds = seconds
end
rescue
puts $!
end
end

end

ServiceDeskResolutionEffort.new(“1:22:10”)

On Mon, Feb 25, 2008 at 9:53 AM, Sijo Kg
[email protected]
wrote:

attr_reader :minutes
In the view
#for exampleday:hour:min


Thanks & Regards,
Pavan A.

NOTICE : This transmission contains information that may be confidential
and
that may also be privileged. Unless you are the intended recipient of
the
message or authorized to receive it for the intended recipient, you may
not
copy, forward, or otherwise use it, or disclose it or its contents to
anyone
else. If you have received this transmission in error please notify us
immediately and delete it from your system.