有沒有辦法在Mongoid中覆蓋模型的setter或getter?喜歡的東西:覆蓋Mongoid模型的setter和getters
class Project
include Mongoid::Document
field :name, :type => String
field :num_users, type: Integer, default: 0
key :name
has_and_belongs_to_many :users, class_name: "User", inverse_of: :projects
# This will not work
def name=(projectname)
@name = projectname.capitalize
end
end
其中name
方法可以在不使用的虛擬域覆蓋?
相關:http://stackoverflow.com/questions/6699503/mongoid-custom-setters-getters-and-super – marcgg