Notes posted by miga
RSS feed
1 thank
Rescuing DeleteRestrictionError via flash message
Model
class ShareType < ActiveRecord::Base has_many :shares, :dependent => :restrict end
Controller
class ShareTypesController < ApplicationController def destroy begin @share_type.destroy flash[:success] = "successfully destroyed." rescue ActiveRecord::DeleteRestrictionError => e @share_type.errors.add(:base, e) flash[:error] = "#{e}" ensure redirect_to share_types_url end end end