Note that there are some explanatory texts on larger screens.

plurals
  1. PODate not writing to database using Rails 3.2 and formtastic
    primarykey
    data
    text
    <p>Before I forget, here's what I'm running with: Rails 3.2.4.rc1 Ruby 1.9.3 Formtastic 2.1 (stable)</p> <p>I'm trying to use formtastic to do user information forms. The date field doesn't seem to be working correctly. All other data is updating correctly. It looks like the PUT request is ok, but when I query my database (mysql), it says that the date = NULL.</p> <p>Code examples:</p> <p>From my view:</p> <pre><code>&lt;%= semantic_form_for @author do |f| %&gt; &lt;%= f.inputs do %&gt; &lt;%= f.input :first_name %&gt; &lt;%= f.input :last_name %&gt; &lt;%= f.input :date_of_birth, :start_year =&gt; Time.now.year-500 %&gt; &lt;%= f.input :nationality %&gt; &lt;%= f.input :bio %&gt; &lt;% end %&gt; &lt;%= f.actions %&gt; &lt;% end %&gt; </code></pre> <p>The PUT request:</p> <pre><code> Started PUT "/authors/4" for 127.0.0.1 at 2012-07-19 11:08:02 -0400 Processing by AuthorsController#update as HTML Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"UARYU7S0FTOLYU1Z04lZp/2Gn94DXiKuX/FN/DgYk/c=", "author"=&gt;{"first_name"=&gt;"Sheila", "last_name"=&gt;"Wedigo", "date_of_birth(1i)"=&gt;"1514", "date_of_birth(2i)"=&gt;"3", "date_of_birth(3i)"=&gt;"5", "nationality"=&gt;"American", "bio"=&gt;"Sheila is an awesome Great American Playwright"}, "commit"=&gt;"Update Author", "id"=&gt;"4"} </code></pre> <p>ETA: Here's the MYSQL in the console:</p> <pre><code>Processing by AuthorsController#create as HTML Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"gjSXdsSWPBzL65fOHX/pe3XTFRau4NYzZSYsyp1aPAs=", "author"=&gt;{"first_name"=&gt;"Stinky ", "last_name"=&gt;"mggee", "date_of_birth(1i)"=&gt;"2010", "date_of_birth(2i)"=&gt;"4", "date_of_birth(3i)"=&gt;"4", "nationality"=&gt;"Finnish", "bio"=&gt;"TEST"}, "commit"=&gt;"Create Author"} SQL (0.2ms) BEGIN SQL (154.1ms) INSERT INTO `authors` (`bio`, `created_at`, `date_of_birth`, `date_of_death`, `first_name`, `last_name`, `nationality`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?, ?, ?) [["bio", "TEST"], ["created_at", Tue, 24 Jul 2012 13:30:23 EDT -04:00], ["date_of_birth", nil], ["date_of_death", nil], ["first_name", "Stinky "], ["last_name", "mggee"], ["nationality", "Finnish"], ["updated_at", Tue, 24 Jul 2012 13:30:23 EDT -04:00]] </code></pre> <p>The output when I ask mysql about it:</p> <pre><code>mysql&gt; select date_of_birth from authors where id = 4; +---------------+ | date_of_birth | +---------------+ | NULL | +---------------+ 1 row in set (0.00 sec) </code></pre> <p>I suspect it might have something to do with the following information from <a href="http://guides.rubyonrails.org/form_helpers.html" rel="nofollow">RoR Guides</a>: "select_date does not work well with forms that update or create Active Record objects as Active Record expects each element of the params hash to correspond to one attribute. The model object helpers for dates and times submit parameters with special names, when Active Record sees parameters with such names it knows they must be combined with the other parameters and given to a constructor appropriate to the column type."</p> <p>That said, I'm not seeing anyone else on the internet with this problem, and it seems like the kind of thing that Formtastic would be handling. This worked correctly before my recent upgrade from Rails 2 to Rails 3.</p>
    singulars
    1. This table or related slice is empty.
    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