Hello, I'm currently using the gem 'nested_set' for comment threading.

What I want to do is prevent the comment level from going more than 2 levels 
deep. What I tired doing was something like this:

    class Comment < ActiveRecord::Base
        ....
        before_save :ensure_max_nestedset_level
      private
    
        # We don't want comments to go more than 2 levels deep. That's 
overkill
        def ensure_max_nestedset_level
          if self.level > 2
            self.level = 2
          end
        end
    
    end


But it looks like you cant set a level only obtain an objects level. With 
the goal being to enforce a MAX of 2 levels deep for comment threading. Can 
anyone suggest a way to enforce that from happening?

The use case being:

    Comment Main (level 0)
 
      Comment Reply (level 1)

        Comment Reply about XXXX (level 2)


When a user replies to the last one (about XXXX) I don't want the comment to 
be set to a level of 3, I want to cap that at 2.

Ideas? Thanks

-- 
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to