Note that there are some explanatory texts on larger screens.

plurals
  1. PONested forms fields_for :prices, repeat forms few time
    primarykey
    data
    text
    <p>i have many to many throught asociation and then i do this</p> <pre><code>fields_for :device </code></pre> <p>this displaying in good way, but i cannot save it i get unknown attribute :price <img src="https://i.stack.imgur.com/a7vUe.png" alt="fields_for :device"></p> <p>And <code>fields_for :devices</code></p> <p><img src="https://i.stack.imgur.com/swauG.png" alt="field_for :devices"></p> <p>And so on, one device makes one more repeat, if i write f<code>.fields_for :price</code> it gives good text field count, but it write </p> <pre><code>unknown attribute: price Rails.root: C:/Users/Ignas/mildai/baze4 Application Trace | Framework Trace | Full Trace app/controllers/commercial_offers_controller.rb:74:in `block in update' app/controllers/commercial_offers_controller.rb:73:in `update' </code></pre> <p>thank you</p> <p>additional information:</p> <p>controller </p> <pre><code> def edit_prices @commercial_offer = CommercialOffer.find(params[:id]) end </code></pre> <p>link to edit prices</p> <pre><code> &lt;%= link_to "Edit prices", :controller =&gt; "CommercialOffers", :action =&gt; "edit_prices", :id =&gt; @commercial_offer %&gt; </code></pre> <p>_edit_price.html.erb </p> <pre><code>&lt;%= form_for @commercial_offer do |f| %&gt; &lt;% CommercialOffer.find(params[:id]).devices.each do |device| %&gt; &lt;%= check_box_tag "commercial_offer[device_ids][]", device.id, @commercial_offer.devices.include?(device) %&gt; &lt;%= device.name %&gt; &lt;%= f.fields_for :prices do |builder| %&gt; &lt;%= render 'prices/new_price', :f =&gt; builder, :commercial_offer =&gt; @commercial_offer, :device =&gt; device %&gt; &lt;% end %&gt; &lt;% end %&gt; &lt;div class="actions"&gt; &lt;%= f.submit "Save"%&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>for one device it have render only one time, but it rendering for one device such times how many devices is with same commercial_offer_id</p> <pre><code>_new_price.html.erb Price: &lt;%= f.text_field :price %&gt;&lt;/br&gt; Quantity: &lt;%= f.text_field :quantity %&gt;&lt;/br&gt; Device id: &lt;%= f.text_field :device_id, :value =&gt; device.id %&gt;&lt;/br&gt; class CommercialOffer &lt; ActiveRecord::Base has_many :prices has_many :devices, :through =&gt; :prices accepts_nested_attributes_for :prices accepts_nested_attributes_for :devices end class Device &lt; ActiveRecord::Base has_many :prices accepts_nested_attributes_for :prices has_many :commercial_offer, :through =&gt; :prices class Price &lt; ActiveRecord::Base belongs_to :device belongs_to :commercial_offer end </code></pre>
    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.
    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