Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 701883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:39:34+00:00 2026-05-14T03:39:34+00:00

i have some Orders that can have several Items and these Items have an

  • 0

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 :items
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>
      <% builder.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 => "kind_change(this)"} %></td>
    <% end %>
      <td><%= builder.text_field :amount, :id => "amountField", :onchange => "change_total_price()" %></td>
      <td><%= builder.text_field :text, :id => "textField" %></td>
      <td><%= builder.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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:39:34+00:00Added an answer on May 14, 2026 at 3:39 am

    You should remove accepts_nested_attributes_for :kinds in Order model and it should be in Item model (as in your code). Then change view here:

    ...
    <% f.fields_for :items do |builder| %>
      <table>
        <tr>
          <% builder.fields_for :kind do |m| %>
    ...
    

    And I think that you have also mistake in following lines:

    <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>
    

    If fields amount, text and price are associated with Item model, then you should use builder instead of f:

    <td><%= builder.text_field :amount, :id => "amountField", :onchange => "change_total_price()" %></td>
    <td><%= builder.text_field :text, :id => "textField" %></td>
    <td><%= builder.text_field :price, :class => "priceField", :onChange => "change_total_price()" %></td>
    

    EDIT (to answer additional questions from comments):

    You should have:

    <% f.fields_for :items do |builder| %>
      <table>
        <tr>
          <td><%= builder.collection_select :kind_id, Kind.find(:all, :order => "created_at DESC"), :id, :name, {:prompt   => "Select a Type" }, {:id => "selector", :onchange => "kind_change(this)"} %></td>  
          <td><%= builder.text_field :amount, :id => "amountField", :onchange => "change_total_price()" %></td>
          <td><%= builder.text_field :text, :id => "textField" %></td>
          <td><%= builder.text_field :price, :class => "priceField", :onChange => "change_total_price()" %></td>
    

    and so on…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to get some nested params. I have an Order that has
I have written some code to ensure that items on an order are all
I have a jar file that uses some txt files. In order to get
I have some a UIView with several user created subviews. The user can move
I have created several custom attributes for my products. I have some that need
I have some SQL that does an order by case statement. It works fine.
I have some things in my app that I need to store, in order
It seems to be common knowledge that hash tables can achieve O(1), but that
Background: I work in a suite of ASP.NET applications that have several different modules.
i have some SQL code that is inserting values from another (non sql-based) system.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.