'Creating an html template based on an html.erb file with embedded method

lets say I have an html.erb file that looks like this:

<div> <%= @creation_time %> </div>

so to get the html with @creation_time embedded in it all I have to do is:

erb = read file content
@creation_time = '2022-04-14 12:02:34 +0300'
template = ERB.new(erb.html_safe)
template.result(binding)

but if I use a method inside the html.erb, for example:

<div> <%= @creation_time.strftime("%-m/%-d/%Y") %> </div>

I get an error

undefined method `strftime' for nil:NilClass

How can I handle this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source