Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3 form error: "undefined method `quoted_table_name'"
    primarykey
    data
    text
    <p>I have a Rails 3 form (simple_form, really) that has a set of nested attributes:</p> <pre><code>&lt;%= simple_form_for(@user, :url =&gt; the_path(@user)) do |f| %&gt; ... &lt;%= f.simple_fields_for :credit_card do |c| %&gt; &lt;%= c.input :number, :label =&gt; 'Credit card number' %&gt; ... &lt;% end %&gt; ... &lt;% end %&gt; </code></pre> <p>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 <a href="http://asciicasts.com/episodes/219-active-model" rel="nofollow">this RailsCast</a>):</p> <pre><code>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 </code></pre> <p>In user.rb, I have this:</p> <pre><code> has_one :credit_card accepts_nested_attributes_for :credit_card </code></pre> <p>When I access the page, I get this error:</p> <pre><code>undefined method `quoted_table_name' for CreditCard:Class </code></pre> <p>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.</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload