Stefano,
Thanks for letting me know. I always playaround with it before I get the
right one. You are right authorized_for_destroy? is the right one. This
is solution# 1 I described below.
Did you try the solution# 2 below? It should return the error message
(as flash [error]).
Sri
Stefano wrote:
> Sri, I've try the solution 1. without result.
> The solution 2. work but I've substitute authorized_for_delete? with
> authorized_for_destroy?.
>
> If ther's no way to display an error message on the view I will use
> authorized_for_destroy?
>
> Thank you very much for your help
>
> On 7 Nov, 19:16, Sri Sri <[EMAIL PROTECTED]> wrote:
>
>> 1. ActiveScaffold is sitting on the top of rails so you can use most of
>> the rails features, if not all.
>>
>> If you put the following in a model, user cannot delete it when it meets
>> the condition (I think the delete link will be automatically disabled in
>> the ActiveScaffold front end). It's prevention than cure.
>>
>> def authorized_for_delete?
>> return false if(do_not_delete_condition)
>> return true
>> end
>>
>> 2. 'before_destroy' call back will display the foolwoing error message
>> when the condition meets and will not destroy.:
>>
>> class Subscription < ActiveRecord::Base
>> before_destroy :check_destroy
>>
>> private
>> def check_destroy
>> errors.add_to_base("Sorry! No! Non! Nein! Nr! ????.!")
>> if(do_not_delete_condition)
>> end
>> end
>>
>> Hope it helps.
>>
>> Stefano wrote:
>>
>>> Sri thank you for reply me but I don't understand:
>>> 1. authorized_for_delete? is a rails method? How can I use it?
>>> 2. the problem is not before_destroy; the validation is ok and in fact
>>> the record is not deleted, I need a way to return to the view a
>>> message like "flash[:notice] = "can't delete"".
>>>
>>> thank you for your help
>>>
>>> On 7 Nov, 18:36, Sri Sri <[EMAIL PROTECTED]> wrote:
>>>
>>>> I think there are two ways to do it. Anyone please correct me if I am
>>>> wrong:
>>>>
>>>> 1. Try the authorized_for_delete? method in the model. That should
>>>> control the delete operations. I find it very useful.
>>>>
>>>> 2. Please look into Canceling callbacks. 'before_destroy' might be
>>>> useful to you.
>>>> http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html#M001622
>>>>
>>>> -Sri
>>>>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---