[英]How do I use simple_form with a plain Ruby class?
I have a credit card class and I'd like to use the simple_form f.input method on the various attributes for use with validations, etc, but I'm getting errors about model_name. 我有一个信用卡类,我想在各种属性上使用simple_form f.input方法用于验证等,但我收到有关model_name的错误。 Is there a simple way to do this?
有一个简单的方法吗?
= simple_form_for @credit_card, url: join_network_path do |f|
.payment-errors
= f.input :card_number
= f.input :cvc
= f.input :expiry_month
= f.input :expiry_year
= f.submit 'Join Network'
You'll need to conform to the ActiveModel API... 您需要符合ActiveModel API ...
Effectively: 有效:
class CreditCard
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
def persisted?
false
end
end
Some background: 一些背景:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.