我一直在 Rails 3 和 Mongoid 上做了一个高峰,并带着对 Grails 中自动脚手架的美好回忆,当我发现: http ://github.com/codez/dry_crud 时,我开始寻找 ruby 的 DRY 视图
我创建了一个简单的类
class Capture
include Mongoid::Document
field :species, :type => String
field :captured_by, :type => String
field :weight, :type => Integer
field :length, :type => Integer
def label
"#{name} #{title}"
end
def self.column_names
['species', 'captured_by', 'weight', 'length']
end
end
但是由于 dry_crud 依赖于 self.column_names 并且上面的类不继承自 ActiveRecord::Base 我必须像上面那样为 column_names 创建自己的实现。我想知道是否可以创建一个返回所有上述字段的默认实现,而不是硬编码列表?