Show many to many relation (tags) as comma separated list in the view

Im new to elixir & phoenix and try to implement a tagging system inspired from this article: http://blog.plataformatec.com.br/2016/12/many-to-many-and-upserts/.

In the HTML form i use a text input where i enter comma separated keywords.

The new function with the form works fine.

def new(conn, _params, _current_user) do
    changeset = Display.change_offer(%Offer{})
    render(conn, "new.html", changeset: changeset)
end

But when i click on save with validation errors i get an error message

lists in Phoenix.HTML and templates may only contain integers representing bytes, binaries or other lists, got invalid entry: #Ecto.Changeset<action: :update, changes: %{}, errors: [], data: #MyApp.Display.Tags<>, valid?: true>

My create action looks like this:

  def create(conn, %{"offer" => offer_params}, current_user) do
    case Display.create_offer(current_user, offer_params) do
      {:ok, offer} ->
        conn
        |> put_flash(:info, "Offer created successfully.")
        |> redirect(to: Routes.offer_path(conn, :show, offer))

      {:error, %Ecto.Changeset{} = changeset} ->
        render(conn, "new.html", changeset: changeset)
    end
  end

I suppose that my text input field can not handle the data and i need some kind of view helper like

<%= text_input f, :tags, value: format_string(changeset.data.tags) %>

Can someone help me? It seems i just don’t get it working.

Nevermind, i solved it using a virtual field

1 Like

hey i have same problem, can you share how to solve this problem?