within my rails application i have a view which does an ajax call for
saving data. what i'd like to do is raise an exception within my
controller that causes the onFailure event to be triggered. for
example
begin
Orderitem.destroy(params[:id])
render :text => "order item deleted"
rescue Exception => e
flash[:notice] = e.message
end
when an exception is captured i.e the rescue exception, how can i
raise an exception; in other langages/platforms i'd construct a 406
(if i remember correctly) response and write a nice message which
would then be captured by the ajax call and prompt the user.
within my rails application i have a view which does an ajax call for
saving data. what i'd like to do is raise an exception within my
controller that causes the onFailure event to be triggered. for
example
begin
Orderitem.destroy(params[:id])
render :text => "order item deleted"
rescue Exception => e
flash[:notice] = e.message
end
when an exception is captured i.e the rescue exception, how can i
raise an exception; in other langages/platforms i'd construct a 406
(if i remember correctly) response and write a nice message which
would then be captured by the ajax call and prompt the user.
any help would be greatly appreciated.
thanks
>
With Rails 2.0 you can now return the status along with the rendered
text. Something like:
begin
Orderitem.destroy(params[:id])
render :text => "order item deleted"
rescue ActiveRecordError => e
render :text => e.message, :status => 406
end