Added module for helper functions; added helper for formatting date consistently

This commit is contained in:
Gregory Ballantine 2023-07-05 22:27:07 -04:00
parent 291db231d5
commit 691e2e9b1e
4 changed files with 16 additions and 4 deletions

8
src/helpers.rb Normal file
View File

@ -0,0 +1,8 @@
module Helpers
def date_format(date)
dt = date.to_datetime
return dt.strftime('%B %d, %Y @ %I:%M:%S %p %Z')
end
end

View File

@ -15,6 +15,10 @@ class GameData < Sinatra::Base
enable :static
set :public_folder, File.join(__dir__, '/../public')
# Register view helpers
require_relative 'helpers'
helpers Helpers
# Set up our view engine
set :views, File.join(settings.root, '/../views')
end

View File

@ -27,8 +27,8 @@
<tr>
<td><%= b.name %></td>
<td><%= b.scoring %></td>
<td><%= b.created_at %></td>
<td><%= b.updated_at %></td>
<td><%= date_format(b.created_at) %></td>
<td><%= date_format(b.updated_at) %></td>
</tr>
<% end %>
</tbody>

View File

@ -27,8 +27,8 @@
<tr>
<td><%= h.name %></td>
<td><%= h.type %></td>
<td><%= h.created_at %></td>
<td><%= h.updated_at %></td>
<td><%= date_format(h.created_at) %></td>
<td><%= date_format(h.updated_at) %></td>
</tr>
<% end %>
</tbody>