如何组织协议实现凤凰

时间:2017-04-14 20:00:35

标签: phoenix-framework multi-select organization

标题可能会误导我的具体问题,但我想在视图中为多选的地图实现Phoenix.HTML.Safe以完成以下操作。

给出架构:

schema "customers" do
    field :owners, {:array, :integer}, virtual: true
    many_to_many :users, User,
                         join_through: CustomerUser,
                         on_delete: :delete_all
end

我想从用户列表中选择客户帐户的owners

因此控制器查询将类似于:

customer = Customer
           |> Repo.get!(id)
           |> Repo.preload(:users)

视图/多选择看起来像:

  <div class="form-group">
    <%= multiple_select f, 
                        :owners, 
                        Enum.map(@customer.users, fn(u)-> %{u.email => u.id} end), 
                        class: "form-control" %>
  </div>

但是这引发了:

  

协议Phoenix.HTML.Safe没有为%{&#34; hulk@hogan.com" =&GT; 2}

那么,如果我为地图实施Phoenix.HTML.safe协议,这段代码应该在哪里生效...... lib

0 个答案:

没有答案
相关问题