I'm using AS (latest master as of 2010-02-26), with dependent_protect,
and the bridge that connects the two.

I have the following code:


class Award
   :habtm => :flags
end

# ========================
class Flag
  :habtm => :awards

private
  def authorized_for_delete?
    return awards.reload.empty?
  end

  # if above check is somehow bypassed (deletion is executed),
  # let's make sure that no dependent records exist before destroying
this one.
  # if there're dependencies, show exception error in a nice yellow-bg
warning in AS
  def before_destroy
    raise ActiveRecord::ReferentialIntegrityProtectionError if !
awards.reload.empty?
  end

end

The whole point of the two methods above is to prevent deletion and/or
errors when attempting to delete records that have dependencies.

So the first Flag method deactivates the "Delete" link in AS if
there're dependent records.
The second Flag method throws an exception if the activated link was
somehow bypassed. For example when another user does not have an up-to-
date version of the list and attempts to delete a Flag, which now has
dependent records (see scenario below).

before_destroy works fine (I get a nice yellow exception warning in
AS) if I try to delete a record with dependencies. Same goes for
authorized_for_delete?, when defined it works as expected (disables
"Delete" link). So each of the methods above work beautifully when
defined individually, but when defined together before_destroy is
never called and I get Error 500 in AS listing. And
ActiveScaffold::RecordNotAllowed exception in the logs.

Scenario:
Two users U1 and U2. U1 creates a whole bunch of Flag records and
starts associating them with some Awards. U2 comes in and decides to
clean up unused flags.
Step1: U1 adds flag "F1"
Step 2: U2 looks at the listing of all Flags (F1 currently has no
dependent records, hence enabled "Delete" action link)
Step 3: U1 associates F1 with some Award.
Step 4: U2 attempts to delete F1.

What happens:
U2 would see Error 500 message in AS listing.

What I would like to happen:
U2 sees yellow error message with error notification

-- 
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