Please explain with example difference between n开发者_StackOverflowamed scope and module.
You would use Named scope if you want to package multiple conditions in Rails such as:
named_scope :active, :conditions => ['active = ?', true]
named_scope :legal_age, :conditions => ['age > ?', 21]
the good advantage of named scopes is you can chain them together. for instance:
user.active.legal_age
Module is used to group similar things together. So normally if you have code that needs to be shared across you app you would define a module in your lib directory and put classes such as.
module MyModule
class MyClass
....
end
end
Module have other use cases, this is the main one from my experience.
精彩评论