Reputation: 5529
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. 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'
Upvotes: 1
Views: 1621
Reputation: 40277
You'll need to conform to the 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:
Upvotes: 4