Ruby: UnknownAttributeError
Posted
by Flexo
on Stack Overflow
See other posts from Stack Overflow
or by Flexo
Published on 2010-03-30T11:43:35Z
Indexed on
2010/03/30
11:53 UTC
Read the original article
Hit count: 273
ruby-on-rails
Hi
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.
Order.rb
class Order < ActiveRecord::Base
validates_presence_of :ref_nr, :total_price
has_many :items, :dependent => :destroy
has_many :kinds, :through => :items
accepts_nested_attributes_for :items
accepts_nested_attributes_for :kinds
validates_associated :items
validates_associated :kinds
end
Item.rb
class Item < ActiveRecord::Base
belongs_to :order
has_one :kind
accepts_nested_attributes_for :kind
validates_associated :kind
end
Kind.rb
class Kind < ActiveRecord::Base
belongs_to :item
end
OrdersController.rb:Create
def create
@order = Order.new(params[:order])
end
new.erb.html
<% form_for @order do |f| %>
<%= f.error_messages %>
<% f.fields_for :items do |builder| %>
<table>
<tr>
<% f.fields_for :kinds do |m| %>
<td><%= m.collection_select :kind, Kind.find(:all, :order => "created_at DESC"), :id, :name, {:prompt => "Select a Type" }, {:id => "selector", :onchange => "type_change(this)"} %></td>
<% end %>
<td><%= f.text_field :amount, :id => "amountField", :onchange => "change_total_price()" %></td>
<td><%= f.text_field :text, :id => "textField" %></td>
<td><%= f.text_field :price, :class => "priceField", :onChange => "change_total_price()" %></td>
<td><%= link_to_remove_fields "Remove Item", f %></td>
</tr>
</table>
<% end %>
<p><%= link_to_add_fields "Add Item", f, :items %></p>
<p>
<%= f.label :total_price %><br />
<%= f.text_field :total_price, :class => "priceField", :id => "totalPrice" %>
</p>
<p><%= submit_tag %></p>
<% end %>
i cant see what im missing
© Stack Overflow or respective owner