ameen
ameen

Reputation: 1

How can I capture date information from a rails form?

I followed a few rails tutorials online, and it seems that to capture a date, I'd use date_select helper. But for some reason or another all the other data is captured in the database (SQLite3) except for the birthday. Any idea what I'm doing wrong?

Here's the code for the form in my view:

  <% form_for :user, :url => {:controller=>'users', :action=> "signup_student"} do |f| %>
    <div>
      <%= f.label :last_name, "Last Name" %><br />
      <%= f.text_field :last_name, :size => 40 %>
    </div>
    <div>
      <%= f.label :birthday, "Birthday" %>
      <%= f.date_select :birthday%>
    </div>
  <% end %>

Any ideas would be awesome. Thanks.

Upvotes: 0

Views: 2935

Answers (1)

Sam 山
Sam 山

Reputation: 42863

Firstly, make sure that your database field type is set to datetime. If it isn't, you can change it with:

change_column :user, :birthday, :datetime

Once you've done that, you can use datetime_select instead of datetime:

<%= f.datetime_select :birthday%>

Upvotes: 3

Related Questions