Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby: UnknownAttributeError
    primarykey
    data
    text
    <p>i have some Orders that can have several Items and these Items have an associated Kind. The Kind can belong to many Items. but i get a "unknown attribute: kinds" in my OrdersController when i hit the submit form button. I use nested forms btw.</p> <p><strong>Order.rb</strong></p> <pre><code>class Order &lt; ActiveRecord::Base validates_presence_of :ref_nr, :total_price has_many :items, :dependent =&gt; :destroy has_many :kinds, :through =&gt; :items accepts_nested_attributes_for :items accepts_nested_attributes_for :kinds validates_associated :items validates_associated :kinds end </code></pre> <p><strong>Item.rb</strong></p> <pre><code>class Item &lt; ActiveRecord::Base belongs_to :order has_one :kind accepts_nested_attributes_for :kind validates_associated :kind end </code></pre> <p><strong>Kind.rb</strong></p> <pre><code>class Kind &lt; ActiveRecord::Base belongs_to :items end </code></pre> <p><strong>OrdersController.rb:Create</strong></p> <pre><code>def create @order = Order.new(params[:order]) end </code></pre> <p><strong>new.erb.html</strong></p> <pre><code>&lt;% form_for @order do |f| %&gt; &lt;%= f.error_messages %&gt; &lt;% f.fields_for :items do |builder| %&gt; &lt;table&gt; &lt;tr&gt; &lt;% builder.fields_for :kinds do |m| %&gt; &lt;td&gt;&lt;%= m.collection_select :kind, Kind.find(:all, :order =&gt; "created_at DESC"), :id, :name, {:prompt =&gt; "Select a Type" }, {:id =&gt; "selector", :onchange =&gt; "kind_change(this)"} %&gt;&lt;/td&gt; &lt;% end %&gt; &lt;td&gt;&lt;%= builder.text_field :amount, :id =&gt; "amountField", :onchange =&gt; "change_total_price()" %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= builder.text_field :text, :id =&gt; "textField" %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= builder.text_field :price, :class =&gt; "priceField", :onChange =&gt; "change_total_price()" %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= link_to_remove_fields "Remove Item", f %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;% end %&gt; &lt;p&gt;&lt;%= link_to_add_fields "Add Item", f, :items %&gt;&lt;/p&gt; &lt;p&gt; &lt;%= f.label :total_price %&gt;&lt;br /&gt; &lt;%= f.text_field :total_price, :class =&gt; "priceField", :id =&gt; "totalPrice" %&gt; &lt;/p&gt; &lt;p&gt;&lt;%= submit_tag %&gt;&lt;/p&gt; &lt;% end %&gt; </code></pre> <p>i cant see what im missing</p>
    singulars
    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.
    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