Search code examples
htmlruby-on-railsformsstrftime

undefined method `strftime' for "{1=>2019, 2=>7, 3=>7, 4=>16, 5=>0}":String Did you mean? strip


I am trying to have the time output in a nice way. Here is my code in new

<%= form_for @reservation do |f| %>
   <span><label>Pick up time</label></span>
     <%= f.time_select :time,ampm: true, class: "textbox"%></span>
<% end %>

And here is in the output file

<strong>Pick up Time:</strong> <%= @reservation.time.strftime("%H:%M")  %>

I got this error undefined method `strftime' for "{1=>2019, 2=>7, 3=>7, 4=>16, 5=>0}":String Did you mean? strip

Please some one help me to fix this


Solution

  • As Sebastian mentions in a comment; it looks as though your time object is a Hash. To call strftime your object needs to be a :datetime.

    To fix this you should change the column type in your database to be that of datetime (As well as changing your forms to save a datetime value).

    An alternative would be to build the string you want to display manually using what is in time (not using strftime).