Thanks Sergio,
This is working now.
I added the appropriate call back to my model.

 before_destroy :address_type?
  
  def address_type?
        errors.add(:base, "Cannot be deleted because it defines existing 
addresses.") unless addresses.count == 0
        errors.blank? #return false
  end


 

On Wednesday, January 30, 2013 1:23:43 PM UTC-7, Sergio Cambra wrote:
>
>  Rescue is getting all exceptions, even PG::Error, in other case you 
> wouldn't get the yellow message. Red message is flash[:error], and it's 
> added when destroy fails to display the validation errors. I have fixed in 
> master to display it only when there are some validation errors.
>
> Also, you could add some checks to a before_destroy callback in the model 
> to avoid that PG::Error if you want. In the callback you can add some error 
> with self.errors.add :base, message and return false. Then you won't get 
> yellow message, only red one with your message.
>
>  
>
> El 30-01-2013 20:46, coalex escribió:
>
> I'm having a weird problem were it looks like Activescaffold is displaying 
> two error warnings when postgresql throws a database error.(on destroy in 
> this example.)
> I posted a screenshot.
>
> The first error (yellow message) displays what I expect to happen, where 
> text from en.yml is displayed for the cant_destroy_record in do_destroy.
>
> here:
>
> module ActiveScaffold::Actions
>   module Delete
>     def do_destroy
>       destroy_find_record
>       begin
>         self.successful = @record.destroy
>       rescue
>         flash[:warning] = as_(:*cant_destroy_record*, :record => 
> @record.to_label)
>         self.successful = false
>       end
>     end
>
>
> and in my  /config/locales/en.yml 
> en:      
> ...
>   active_scaffold:
> ...
>     # error_messages
>     cant_destroy_record: "%{record} can't be destroyed! <<My Custom 
> Message!>>"
>
> ---
> The second error (red bar) displays under the first, contains no text and 
> requires a click to close. Where is that one coming from, how do I stop it 
> from displaying?
>
>  I thought this might be a result of not handling the Pg::error so I tried 
> something like this in my application Controller.
>
>    rescue_from PG::Error do |exception|
>     puts "foo"
>   end
>
> Didn't help!
>
> At this point I'm trying to figure out how to rescue a PG error without 
> activescaffold displaying two error bars.
> Thank you for any advice.
>
> env
> Rails 3.2.8
> Ruby 1.9.2
> pg 0.14.1
>
>  
> -- 
> You received this message because you are subscribed to the Google Groups 
> "ActiveScaffold : Ruby on Rails plugin" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> To post to this group, send email to [email protected]<javascript:>
> .
> Visit this group at http://groups.google.com/group/activescaffold?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  
>
>  
>  
>  

-- 
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/activescaffold?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to