Jonathan Linowes 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
> end
>
> # Question: 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
--
Posted via http://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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---