Your associations are incorrect. Both Role and CriticalProcess refer to each other via has_many -- one of them must use belongs_to. And where is the Authorization class? What is it's relationship to CriticalProcess?
Fix the associations problem and the loop will likely go away. Why? I suspect because the CriticalProcess has_many :roles implies that Role belongs_to it. Thus, ActiveRecord creates its own create_roles for you. See http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_many. Notice the methods you get for free with each kind of assocation. Nothing will work the way you have it defined now. Martin On Mar 10, 2:46 pm, Mo Al <[email protected]> wrote: > 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 > > -- > Posted viahttp://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" 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/rubyonrails-talk?hl=en.

