The main concern with default_scope is that it's not more in use when your chaining multiple scopes, so you can't put the logic of "scoping to the current user" in your models.
I believe that the genuine usage of AR associations (has_many :orders), should do the trick of retrieving only the orders related to the user performing action in your application.
If you want to secure your objects now, you could either use an authorization system (like ACL9) or implement your own like, in your case, putting in your model:
# Order model
class Order < AR::Base
belongs_to :customer
def is_allowed_to(action, performer)
case action
when 'show'
performer.id == self.customer.id
when 'update'
performer.id == self.customer.id
when 'destroy'
performer.is_a? Administrator
....
end
end
Then in your controllers that handle orders, you could use the before filter
to retrieve the actual object in the DB and call the method is_allowed_to
to check permissions.
The action
parameter would be either the actual action name or another one of your choice.
I hope it'll help.