如何获取ActiveRecord属性方法功能?我有这个类:ActiveModel属性
class PurchaseForm
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :name,
:surname,
:email
validates_presence_of :name
validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
def initialize(attributes = {}, shop_name)
if not attributes.nil?
attributes.each do |name, value|
send("#{name}=", value)
end
end
def persisted?
false
end
end
我需要做什么,有一个属性方法列出来自PurchaseForm对象的所有名称和值?
鉴于哈克现有的答案,正确的答案似乎是“没有Rails的模块那”。就个人而言,我会避免模仿属性API。 – vemv 2016-10-17 15:47:08