Is it possible to create a column or to change one to type date with default format?
something like:
def change
change_column :mytable, :mydate, :date [:default]="%d/%m/%Y"
end
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To my knowledge no. But why on Earth would you want to do that?
Rails will pull out a date and automagically make it a Date/Time (according to your column type) object. If you need to display your date differently I strongly suggest the use of strftime like so:
Here’s a list of the different options: http://www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime
Update
Make use of decorators with Draper: https://github.com/drapergem/draper
I would recommend renaming the method but for now if you don’t want to you could simply override it doing this:
You would it like so:
In it’s default state, the date returned will not be formatted which is fine.
If you have to do
where("date.strftime('%d/%m/%Y') >= ?",fdate, you’re doing it wrong. Again, stick to the default format.