Why isn't the format date of the Rails view being properly displayed with the initializer?

38 views Asked by At

On my view view, I have the following format I want to output:

<tr>
  <th>Released:</th>
  <td>
   <%= movie.release_at.to_s(:release_date) %>
   (<%= time_ago_in_words(movie.release_at) %>)
  </td>
</tr>

The exact format I want is "Month Day, Year", so I created an initialize file with the following:

Date::DATE_FORMATS[:default] = "%B %e, %Y"

My database schema has a movies table with a field called release_at with the data type of datetime this is where I am attempting to extract the the data.

1

There are 1 answers

2
infused On BEST ANSWER

You've set the default Date format, but you said that the column is a datetime. If you want the default Date format that you specified, you'll need to convert the value to a date:

<%= movie.release_at.to_date.to_s %>