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 <td><table><tr> <th width=""><label for="" >Day: </label></th> <td><%= text_field :sd_resol, "days", "size" => 2 %></td> <th width=""><label for="" >Hr: </label></th> <td><%= text_field :sd_resol, "hours", "size" => 2 %></td> <th width=""><label for="" >Min: </label></th> <td><%= text_field :sd_resol, "minutes", "size" => 2 %></td> 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 -- 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-/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 -~----------~----~----~----~------~----~------~--~---
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 <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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 > > <td><table><tr> > <th width=""><label for="" >Day: </label></th> > <td><%= text_field :sd_resol, "days", "size" => 2 %></td> > <th width=""><label for="" >Hr: </label></th> > <td><%= text_field :sd_resol, "hours", "size" => 2 %></td> > <th width=""><label for="" >Min: </label></th> > <td><%= text_field :sd_resol, "minutes", "size" => 2 %></td> > > 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 > -- > Posted via http://www.ruby-forum.com/. > > > >-- Thanks & Regards, Pavan Agrawal 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. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
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 -- 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-/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 -~----------~----~----~----~------~----~------~--~---