I have a Rails 3 form (simple_form, really) that has a set of nested attributes:
<%= simple_form_for(@user, :url => the_path(@user)) do |f| %>
...
<%= f.simple_fields_for :credit_card do |c| %>
<%= c.input :number, :label => 'Credit card number' %>
...
<% end %>
...
<% end %>
The problem is that the :credit_card attributes belong to the class CreditCard, which is not a model since I'm not storing any of the credit card data in the database. I have that Class defined in /app/models/credit_card.rb like this (per this RailsCast):
class CreditCard
include ActiveModel::Validations
include ActiveModel::Conversion
include ActiveModel::Naming
attr_accessor :number, :expiration_month, :expiration_year, :cvv
validates_presence_of :number, :expiration_month, :expiration_year, :cvv
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
def persisted?
false
end
end
In user.rb, I have this:
has_one :credit_card
accepts_nested_attributes_for :credit_card
When I access the page, I get this error:
undefined method `quoted_table_name' for CreditCard:Class
Googling that error didn't yield any suggestions. I'm able to create CreditCard objects from Rails Console, but for some reason the Rails form generator isn't seeing the class.
I already tried swapping out simple_form_for with form_for (and the related changes), so I don't think it's a simple_form problem.