diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 990feca..e1e3dbc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,16 +5,21 @@ class ApplicationController < ActionController::Base rescue_from CanCan::AccessDenied, ActiveScaffold::ActionNotAllowed do |exception| flash.now[:error] = exception.message - render :template => 'errors/access_denied', :layout => 'errors' + render_access_denied end rescue_from ActiveScaffold::ActionNotAllowed do |exception| flash.now[:error] = I18n.t("errors.action_not_allowed") - render :template => 'errors/access_denied', :layout => 'errors' + render_access_denied end protected + def render_access_denied + layout = request.xhr? ? false : 'errors' + render :template => 'errors/access_denied', :layout => layout + end + def ensure_nested_under_domain raise CanCan::AccessDenied, "not found" unless nested? and nested_parent_record.is_a?(Domain) end diff --git a/app/controllers/ns_controller.rb b/app/controllers/ns_controller.rb index 1dc269b..7bf6f66 100644 --- a/app/controllers/ns_controller.rb +++ b/app/controllers/ns_controller.rb @@ -35,4 +35,11 @@ class NsController < ApplicationController nested_singular_association? # || params[:parent_sti] end + def do_destroy + super + if successful? && nested_parent_record.ns_records.count == 0 + flash[:warning] = "All NS records deleted, no other nameservers are associated with this domain!" + end + end + end diff --git a/app/models/domain.rb b/app/models/domain.rb index 941ac8d..acd2cd8 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -30,7 +30,7 @@ class Domain < ActiveRecord::Base validates :type, :inclusion => { :in => @@types, :message => "Unknown domain type" } validates :soa_record, :presence => {:unless => :slave?} validates_associated :soa_record #, :allow_nil => true - validates :ns_records, :presence => true, :length => { + validates :ns_records, :on => :create, :presence => true, :length => { :minimum => 2, :maximum => 10, :message => "must have be at least 2, at most 10"} validates_associated :records