协议Phoenix.HTML.Safe没有实现Elixir Phoenix

时间:2016-12-05 10:08:13

标签: elixir phoenix-framework

我有一个像

这样的值的对象
%{"Friday" => [], "Monday" => [], "Saturday" => [], "Sunday" => ["3:0-4:0", "6:0-7:0"], "Thursday" => [], "Tuesday" => [], "Wednesday" => []}

我想在我的电子邮件模板的视图中显示它,我刚才声明为

<p>Schedule: <%= @schedule %></p>

我收到了这个错误

** (Protocol.UndefinedError) protocol Phoenix.HTML.Safe not implemented for %{"Friday" => [], "Monday" => [], "Saturday" => [], "Sunday" => ["3:0-4:0", "6:0-7:0"], "Thursday" => [], "Tuesday" => [], "Wednesday" => []}

在HTML中显示它的最佳方式是什么?

1 个答案:

答案 0 :(得分:10)

你无法直接输出这样的地图;只有实现Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); DateTime currentCultureDate = DateTime.Now; string format = "dd.MM.yyyy HH:mm:ss"; Console.WriteLine("Format: " + format); Console.WriteLine("Original Date: " + currentCultureDate); DateTime convertedDate = DateTime.ParseExact(currentCultureDate.ToString(), format, new CultureInfo("de-DE")); Console.WriteLine("Converted Date: " + convertedDate); 协议的东西。如果要打印Phoenix.HTML.Safe将打印的内容(如果可能,则为Elixir语法),您可以显式调用iex将Map转换为字符串,然后输出:

inspect

如果您想以不同的方式打印,可以使用<p>Schedule: <%= inspect @schedule %></p>

for