Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass an object in a radio button tag?
    primarykey
    data
    text
    <p>For my form I am using my <code>Product</code> model:</p> <pre><code>class Product &lt; ActiveRecord::Base attr_accessible :purchase_date, :send_to_data end </code></pre> <p>On my form I have the <code>:purchase_date</code> working correctly when I create multiple products but also want to make the radio_button_tag do the same:</p> <pre><code>&lt;%= form_tag create_multiple_products_path, :method =&gt; :post do %&gt; &lt;%= date_select("product", "purchase_date") %&gt; &lt;%= radio_button_tag(:send_to_data, 1) %&gt; &lt;%= radio_button_tag(:send_to_data, 0) %&gt; &lt;% @products.each_with_index do |product, index| %&gt; &lt;%= fields_for "products[#{index}]", product do |up| %&gt; &lt;%= render "fields", :f =&gt; up %&gt; &lt;% end %&gt; &lt;% end %&gt; &lt;%= submit_tag "Done" %&gt; &lt;% end %&gt; </code></pre> <p>This didn't work for me, my database doesn't flag as either false or true.</p> <p>I think the problem lies in the params of the <code>"send_to_data"</code>. Unlike the <code>"purchase_date"</code> it isn't finding the object (product).</p> <pre><code>{"product"=&gt;{"purchase_date(2i)"=&gt;"12", "purchase_date(3i)"=&gt;"11", "purchase_date(1i)"=&gt;"2011"}, "send_to_data"=&gt;"1", "products"=&gt;{"0"=&gt;{"product_name"=&gt;"Test", "price"=&gt;"23", "product_store"=&gt;"13", "exact_url"=&gt;""}, "1"=&gt;{"product_name"=&gt;"", "price"=&gt;"", "product_store"=&gt;"", "exact_url"=&gt;""}, "2"=&gt;{"product_name"=&gt;"", "price"=&gt;"", "product_store"=&gt;"", "exact_url"=&gt;""}, "3"=&gt;{"product_name"=&gt;"", "price"=&gt;"", "product_store"=&gt;"", "exact_url"=&gt;""}, "4"=&gt;{"product_name"=&gt;"", "price"=&gt;"", "product_store"=&gt;"", "exact_url"=&gt;""}}, "commit"=&gt;"Done"} </code></pre> <p>Is there a way to map it to the object like the purchase date does?</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