ruby exception handling

S

Sijo Kg

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]
save_result=@pb_activity.save!
if !params[:pb_activity_attachment][:attachment].blank?
if save_result
@pb_activity_attachment=ProblemActivityAttachment.new(params[:pb_activity_attachment])
@pb_activity_attachment.problem_activity_id=@pb_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", :eek:bject => @pb_activities,
:eek:bject => @problem
end
end #respond_to do end
end
 
R

Roger Pack

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]
save_result=@pb_activity.save!
if !params[:pb_activity_attachment][:attachment].blank?
if save_result
@pb_activity_attachment=ProblemActivityAttachment.new(params[:pb_activity_attachment])
@pb_activity_attachment.problem_activity_id=@pb_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", :eek:bject => @pb_activities,
:eek:bject => @problem
end
end #respond_to do end

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

Sijo Kg

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,629
Members
45,330
Latest member
AlvaStingl

Latest Threads

Top