Note that there are some explanatory texts on larger screens.

plurals
  1. POExtracting value from a param *name*?
    primarykey
    data
    text
    <p>I have a list of params with names and values like this:</p> <pre><code>date_2009-09-16 =&gt; ["50.00"] date_2009-09-17 =&gt; ["60.00"] date_2009-09-18 =&gt; ["90.00"] </code></pre> <p>I would like to save a record in my database for each date like this:</p> <pre><code>|id | date | price| |1 | 2009-09-16 | 50.00| |2 | 2009-09-17 | 60.00| |3 | 2009-09-18 | 90.00| </code></pre> <p>How do I extract the date from the param name (is this possible?!) ?</p> <p><strong>Update:</strong></p> <p>Whilst I'm still not sure about how to do Eimantas' answer, can I clarify the params my form is sending:</p> <pre><code>Parameters: { "commit"=&gt;"Save", "method"=&gt;"put", "controller"=&gt;"rates", "action"=&gt;"create", "authenticity_token"=&gt;"A0wP8Dq7cVOM+bLIcdPENzRhg6T1Mwhjqob1UYTk1Jk=", "date_2009-09-16"=&gt;"50.00", "date_2009-09-17"=&gt;"60.00", "date_2009-09-18"=&gt;"90.00", "rate"=&gt;{"year"=&gt;"2009", "product_type_id"=&gt;"2"} } </code></pre> <p>I think the dates should belong inside the rate part of the params hash, but Rails isn't putting them in there.</p> <p><strong>Update 2:</strong></p> <p>I'm wondering if you can see my Rate table, then it might help nail this for me (and prevent your frustration!). I'm trying to allow a customer to put 30 values in 30 boxes in my view (one for each day of September in this example), and in my controller, after they've hit Save, have it save the 30 records.</p> <pre><code>id | date | price | product_type_id | .. | .. | .. | .. | 16 | 2009-09-16 | 50.00 | 1 | 17 | 2009-09-17 | 60.00 | 1 | 18 | 2009-09-18 | 90.00 | 1 | .. | .. | .. | .. | </code></pre> <p>I thought about using one hidden field to hold the date, and one visible field to hold the price, but how will Rails know which date goes with which price in the create action? Sorry if this is so confusing.</p> <p>Thanks in advance!</p> <p>Gav</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