Ruby exception handling

Hi
I have been learning exception handling in ruby.I am not familiar
with the exception handling mechanisms (The project which I am working
is my first project and it is in Ruby)…Could anyone explain me how to
add exception handling coding for the following fragment Then it will be
very valuable for me to understand exception handling mechanisms in
ruby.Here what I am doing is first add an activity to the
problem_activities table (which has problem_id as one of its field) and
if there is attachment for that activity, that is added to
problem_activity_attachments table (which has problem_activity_id as one
of its column)

def pb_activity_attach_file
@problem=Problem.find(params[:id])
ActiveRecord::Base.transaction do
@pb_activity=ProblemActivity.new(params[:pb_activity])
@pb_activity.problem_id= params[:id]
[email protected]_activity.save!
if !params[:pb_activity_attachment][:attachment].blank?
if save_result
@pb_activity_attachment=ProblemActivityAttachment.new(params[:pb_activity_attachment])
@[email protected]_activity.id.to_i
@pb_activity_attachment.save!
end
end
end #end of transaction
@[email protected]_activities.pb_activities_paginate(params[:page])
responds_to_parent do
render :update do |page|
page[:pb_create_activity_ui].replace :partial =>
“problem_part/view_pb_activity_details”, :object => @pb_activities,
:object => @problem
end
end #respond_to do end
end

Sijo Kg wrote:
here ya go:

def pb_activity_attach_file
begin
@problem=Problem.find(params[:id])
ActiveRecord::Base.transaction do
@pb_activity=ProblemActivity.new(params[:pb_activity])
@pb_activity.problem_id= params[:id]
[email protected]_activity.save!
if !params[:pb_activity_attachment][:attachment].blank?
if save_result
@pb_activity_attachment=ProblemActivityAttachment.new(params[:pb_activity_attachment])
@[email protected]_activity.id.to_i
@pb_activity_attachment.save!
end
end
end #end of transaction
@[email protected]_activities.pb_activities_paginate(params[:page])
responds_to_parent do
render :update do |page|
page[:pb_create_activity_ui].replace :partial =>
“problem_part/view_pb_activity_details”, :object => @pb_activities,
:object => @problem
end
end #respond_to do end

 rescue Exception => e
    # can retry, or raise or what not
 end

end

Hi
Thanks for your reply.Actually I expect some elaborate reply.So I
need to put the whole def in one begin-end…Why i expect such some
elaborate reply means actually i am new to exception handling in any
language(Since as I told this is my first project ) Again thanks for the
reply

Sijo

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs