我有一个控制器FormsController和一个Active Model ApplicationForm。我通过加入>>> ln = len(ec2.get_all_security_groups())
>>> print ln
8
>>> dir(ln)
['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', '__floordiv__', '__format__', '__getattribute__', '__getnewargs__', '__hash__', '__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 'bit_length', 'conjugate', 'denominator', 'imag', 'numerator', 'real']
>>>
,include ActiveModel::Validations
,include ActiveModel::Conversion
来制作此模型。当我使用extend ActiveModel::Naming
时,我正在@form=ApplicationForm
。如何解决此问题,我只想将此模型用作类,它可以提供临时保存表单值的对象以供进一步处理。
答案 0 :(得分:0)
以下是如何从目录中使用它。假设它位于app / forms目录中,并且您已经正确地将表单添加到rails的自动加载路径中。
@form = ::Forms::ApplicationForm.new(your_params)
您的模块必须像这样命名
module Forms
class ApplicationForm
#your form code
end
end