Ruby on Rails latest stable (v7.1.3.2)
-
1 note
- Superclass:
ActiveRecord::ActiveRecordError
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0 (0)
- 3.0.9 (-38)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (0)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
This error is raised when trying to destroy a parent instance in N:1 or 1:1 associations (has_many, has_one) when there is at least 1 child associated instance. ex: if @project.tasks.size > 0, DeleteRestrictionError will be raised when trying to destroy @project
Register or
log in
to add new notes.
miga -
July 31, 2011 - (>= v3.0.9)
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