I have looked through the Ruby on Rails guides and I can\'t seem to figure out how to prevent someone from deleting a Parent record if it has Children. For example. If my
One possibility would be to avoid providing your users a link to deletion in this scenario.
link_to_unless !@customer.orders.empty?
Another way would be to handle this in your controller:
if !@customer.orders.empty?
flash[:notice] = "Cannot delete a customer with orders"
render :action => :some_action
end
Or, as Joe suggests, before_filters could work well here and would probably be a much more DRY way of doing this, especially if you want this type of behavior for more models than just Customer.