Check this code:

class Client < ActiveRecord::Base
        validates_presence_of :name, :itin, :address
        validates_uniqueness_of :itin

        has_many :invoices, :dependent => :protect

        def initialize(attrs = {}, &block)
                super
                self.active ||= true
        end
end

class ClientController < ApplicationController
  active_scaffold :client do |config|
    config.label = "Clientes"
    config.columns = [:name, :itin, :address, :active, :invoices]
    config.update.columns = config.create.columns =
[:name, :itin, :address, :active]
    columns[:name].label = "Nombre"
    columns[:itin].label = "NIT"
    columns[:address].label = "Dirección"
    columns[:active].label = "Activo"
    columns[:invoices].label = "Facturas"
    config.print_pdf.header_text = "Lista de clientes"
  end

  def destroy
    begin
      super
    rescue ActiveRecord::ReferentialIntegrityProtectionError
      send_flash('Imposible borrar porque hay registros relacionados')
    end
  end
end

On 7 ago, 14:41, Swartz <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm trying to use ActiveScaffold pluging for an admin interface along
> with dependent => protect plugin (http://ruido-blanco.net/blog/rails-
> dependent-protect-plugin-english/).
>
> Depending -> protect plugin's job is to raise an
> ActiveRecord::ReferentialIntegrityProtectionError exception whenever I
> try to delete a has_many relation which has child records. Example:
>
> class Company < ActiveRecord::Base
>   has_many :employees, :dependent => :protect
> end
>
> class Employee < ActiveRecord::Base
>   belongs_to :company
> end
>
> So that exception should be raised whenever company is being deleted
> which has employees associated with it.
> It works all fine and dandy if I use my own controller code to edit/
> delete records. But since I'm using ActiveScaffold in my controller, I
> dont know where to  put the rescue clause to catch that exception.
>
> Any info would be welcome!
>
> Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to