2016-12-05 61 views
1

我有這樣的值對象作爲協議Phoenix.HTML.Safe沒有實施藥劑鳳凰

%{"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中?

回答

4

你不能直接輸出這樣的地圖;只有執行Phoenix.HTML.Safe協議的事情。如果你想打印什麼iex將打印(這是花好月圓語法如果可能的話),你可以顯式調用inspect的地圖轉換爲字符串,然後是輸出:

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

如果你想打印在以不同的方式,您可以使用for

<p> 
    Schedule: 
    <%= for {key, value} <- @schedule do %> 
    ...use key and value variables here... 
    <% end %> 
</p>