开发者

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 fo开发者_如何学Pythonrm 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.


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%>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜