Uninitialized constant Item::Types
- by Rasmus
Hi!
First of, im a newbie ruby programmer so please bare with me if this is a very dumb question.
I get this uninitialized constant error when i submit my nested forms.
order.rb
class Order < ActiveRecord::Base
has_many :items, :dependent => :destroy
has_many :types, :through => :items
accepts_nested_attributes_for :items
accepts_nested_attributes_for :types
validates_associated :items
validates_associated :types
end
item.rb
class Item < ActiveRecord::Base
has_one :types
belongs_to :order
accepts_nested_attributes_for :types
validates_associated :types
end
type.rb
class Type < ActiveRecord::Base
belongs_to :items
belongs_to :orders
end
new.erb.html
<% form_for @order do |f| %>
<%= f.error_messages %>
<% f.fields_for :items do |builder| %>
<table border="0">
<th>Type</th>
<th>Amount</th>
<th>Text</th>
<th>Price</th>
<tr>
<% f.fields_for :type do |m| %>
<td> <%= m.collection_select :type, Type.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><%= f.submit "Create"%></p>
<% end %>
<%= link_to 'Back', orders_path %>
create method in orders_controller.rb
def create
@order = Order.new(params[:order])
respond_to do |format|
if @order.save
flash[:notice] = 'Post was successfully created.'
format.html { redirect_to(@order) }
format.xml { render :xml => @order, :status => :created,
:location => @order }
else
format.html { render :action => "new" }
format.xml { render :xml => @order.errors,
:status => :unprocessable_entity }
end
end
end
Hopefully you can see what i cant