2

I have a model where a group has several capabilities

class Group < ActiveRecord::Base
  attr_accessible :capabilities_attributes

  acts_as_audited #<------------------------------- source of error
  has_associated_audits

  has_many :capabilities, :dependent => :destroy
end


class Capability < ActiveRecord::Base
  acts_as_audited :associated_with => :entity_group 
end

And a controller where I have

class GroupsController < ApplicationController  
  load_and_authorize_resource   #cancan authorization

  #...

  def update
    if @group.update_attributes(params[:group])
      flash[:notice] = "Group '#{@group}' has been updated."
      redirect_to groups_path
    else
      flash[:alert] = "Group '#{@group}' was not updated."
      render :action => "edit"
    end
  end

end

The problem with that plugin (and it does that in other similar situatinos) is that when updating the group capabilities, it tries to insert it twice.

I am not sure why the update of attributes occurs twice. It is fine when I don't use acts_as_audited (or other plugins). But as soon as I add something, I have a duplication error.

I assume there is some early insertion that must occur, but I can't find any reason why it is triggered (and how to prevent it) once too many when, and only when, there are intefering plugins.

Has anyone encountered such an issue ? (or successfully implemented acts_as_audited with nested attributes?)

Many thanks for your help and insights

user1251614
  • 529
  • 3
  • 11

0 Answers0