Hi In the controller I have the function
def convert_sd_ticket_to_incident ServiceDeskTicket.close_ticket(sd_id,created_by_id,modified_by_id) Incident.convert_sd_ticket_to_incident(sd_id,created_by_id,modified_by_id) end
Now in the ServiceDeskTicket model def self.close_ticket(sd_id,created_by,modified_by) begin ActiveRecord::Base.transaction do sd_ticket=self.find(sd_id) sd_ticket.service_desk_status_histories.add_status_histories_on_convert_to_incident(sd_ticket.id,sd_ticket.service_desk_status_id,created_by,modified_by) sd_ticket.update_attributes!(:service_desk_status_id => 7 ) code continues end rescue Exception => e: puts 'error is '+e.to_s end end
Now my problem is this ServiceDeskTicket has a validation validates_presence_of :description It is only implemented now and there are some records in the db which have no description..So suppose if I tries to convert any such record to an incident what happens is the above code in the model ServiceDeskTicket rollsback since it gets exception that description empty...But what happens now is in the controller code above the rest ie Incident.convert_sd_ticket_to_incident(sd_id,created_by_id,modified_by_id) which is executed (this code converts the ticket to incident) The solution which i am searching is how can I handle (get) the above exception that is happening in the model in the controller and redirect to the same page saying that "Please give a description first" I know I can restrict the Incident being added to check whether the return value of ServiceDeskTicket.close_ticket(sd_id,created_by_id,modified_by_id) is true But how can I handle this.Please help
Sijo