class Person < ActiveRecord::Base
def before_destroy
errors.add_to_base "You will never destroy me!!"
false
end
end
p = Person.find(:first)
p.destroy # false
p.errors # will include the above error
-Jonathan.
On 6/30/06, Randal Santia <randal@b2blogic.net>
wrote:> Hey, probably an easy question but,
>
> I''m trying to get a method to run "before_destory" for a
model, and I
> want the method to throw an error, and not delete the object from the
> database, if a certain condition is held
>
> Obviously, I can just raise an error and rescue it... but for some
> reason I can''t get <% error_messages_for ''model"
%> to catch and display
> the error... isntead I just get the Ruby error page..
>
> I''m sure the reason I can''t get this to work is because
I''m new to ruby,
> and I''m not thinking right, but any tips, or suggestions would be
> appritiated, thanks!
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>