문제

This is a simple question. I want to create a column that stores the date of creation - not the datetime which created_at and created_on do. How do I do this?

Edit: I mean the date of the model record. So for example, when a user creates a micropost, I would like to store just the date, and not the datetime.

도움이 되었습니까?

해결책 2

Pavan answered my question in the comment. If you add a column with Date as its datatype, it will automatically set the field to date of creation.

다른 팁

Create an additional column inside table by creating an extra migration to add that extra column and save the below value while saving the record:

Time.now.s­trftime("%­Y-%m-%d")

Hope it helps :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top