lets say this is a comments model, acts_as_tree
used like this @post.comments.find_roots
def self.find_roots(options = {})
with_scope :find => options do
self.find(:conditions => [‘parent_id IS NULL’], :order
=> :position )
end
end
def self.find_roots(options = {})
with_scope :find => options do
self.find(:conditions => [‘parent_id IS NULL’], :order
=> :position )
end
end
Jonathan L. wrote:
lets say this is a comments model, acts_as_tree
used like this @post.comments.find_roots
def self.find_roots(options = {})
with_scope :find => options do
self.find(:conditions => [‘parent_id IS NULL’], :order
=> :position )
end
endQuestion: how can i enforce any call is scoped by project_id?
(I dont want to allow Post.find_roots, it must have a project_id)
You can define it on your association, if you only want that method
accessible via the association.
class Post < ActiveRecord::Base
has_many :comments do
def find_roots(options = {})
#…
end
end
end
Now you can do @post.comments.find_roots but not Post.find_roots
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs