I am trying to use Formtastic to create a payment form, since I would like to use inline errors. I use ActiveMerchant to handle billing. I have the following form:
<%= semantic_form_for @payment do %>
<%= form.inputs do %>
<%= form.input :email, :label => "Email Address" %>
<%= form.semantic_fields_for :credit_card_attributes do |cc| %>
<%= cc.input :number, :label => "Credit Card Number" %>
<%= cc.input :first_name, :label => "First Name" %>
<%= cc.input :last_name, :label => "Last Name" %>
<%= cc.input :month, :label => "Expiration Month" %>
<%= cc.input :year, :label => "Expiration Year" %>
<%= cc.input :verification_value, :label => "Verification Code" %>
<% end %>
<% end %>
<% end %>
And here is what is in my model Payment:
class Payment < ActiveRecord::Base
validates_associated :credit_card, :on => :create
def credit_card_attributes=(attrs)
@credit_card = ActiveMerchant::Billing::CreditCard.new(attrs)
end
def credit_card
@credit_card
end
end
When I send an invalid credit card, it indicates that it is invalid, but I do not receive any built-in errors from formtastic.
I suppose that maybe something simple is missing here, I'm just not sure what.
This is on Rails 3.
source
share