I have a model named: Event
And I don't want anyone to destroy or update any records in Event
model.
So:
[code]
class ActiveRecord::Base
before_destroy :log_illegal_operations
before_update :log_illegal_operations
private
def log_illegal_operations
Event.create({:key => "illegal operation", :value => "Someone
wants to update/destroy record(s) in Event model. Blocked!"})
raise ActiveRecord::ReadOnlyRecord, "This is a readonly model, do
not destroy any record!"
# return false
end
end
[/code]
But, it won't create any events but the auto_increment will be
increment.
Do anybody knows how to solve it?
If I set read-only to the model, then I can't create any event
anymore
I just want to block anyone to update/destroy records, but I need to
create records
If I set read-only to the model, then I can't create any event
anymore
I just want to block anyone to update/destroy records, but I need to
create records
Check whether new_record? is true before returning false from your
callback ?
I have a model named: Event
And I don't want anyone to destroy or update any records in Event
model.
[snip]
But, it won't create any events but the auto_increment will be
increment.
Do anybody knows how to solve it?
Thanks!
The problem you've run into is that the callbacks run inside a
transaction - throwing the ReadOnlyRecord exception rolls the whole
thing back (including the Event record).
Is there some reason that this can't be done in the UI? Just don't
provide the update and delete options...