Hi
I am getting a Stack level too deep error when i try creating a new
critical process object:
here is the code:
class Role < ActiveRecord::Base
has_many :authorizations
has_many :critical_processes, :through => :authorizations
has_many :assignments
has_many :users, :through => :assignments
end
class CriticalProcess < ActiveRecord::Base
has_many :authorizations
has_many :roles, :through => :authorizations, :dependent => :destroy,
:primary_key => :cp_secondary_id
after_create :new_cp
def create_roles
self.roles.create :name => “#{self.cp_title} edit”,
:critical_process_id => self.id, :edit => true, :review => false
self.roles.create :name => “#{self.cp_title} review”,
:critical_process_id => self.id, :edit => false, :review => true
end
def set_secondary_id
self.update_attribute :cp_secondary_id, self.id
end
def new_cp
if self.cp_secondary_id.blank?
set_secondary_id
create_roles
end
end
end
here is the error from the log:
SystemStackError (stack level too deep):
app/models/critical_process.rb:17:in create_roles' app/models/critical_process.rb:31:in
new_cp’
app/controllers/critical_processes_controller.rb:61:in create' app/controllers/critical_processes_controller.rb:60:in
create’
The issue is arising when the “create_roles” method is getting called.
Anyone know how i can fix this problem, i am new to rails and web
development. what changes would i have to make?
Thank You