Getting json view error

I have a user schema. From which I have to fetch showing certain fields. So I have two controllers and both are fetching the data from same model.

So here is my profiles_view j

defmodule AppWeb.ProfilesView do
  use AppWeb, :view
  alias AppWeb.ProfilesView

   def render(action, params) do
    IO.inspect action
    IO.inspect params

  def render("profiles.json", %{profiles: profiles}) do
    %{data: render_many(profiles, ProfilesView, "profile.json")}

  def render("profile.json", result) do

But here I’m getting data in my profiles. So I did inspect action and params. So in action I’m getting “profiles.json” and
in params assigns

      layout: false,
      profiles: %App.Auth.User{
        __meta__: #Ecto.Schema.Metadata<:loaded, "itlabs", "user">,
        avatar: nil,
        background: nil,
        created_date: ~N[2020-04-20 18:58:24],
        email: "",

But when I call after first render function I’m getting this kind of error

** (exit) an exception was raised:
** (Protocol.UndefinedError) protocol Enumerable not implemented

This error related to the data I’m receiving. But I want to know why the layout is false?
Please check assigns

Can you show the call to render/3 in your controller? Are you sure you are not passing layout: false as an assign?

EDIT: I am mistaken. The reason why you see layout: false is explained here. The :layout key is a reserved assign set by Phoenix for layout rendering.

1 Like

I’m just doing this

  def get_profiles(conn, _params) do
    profile = Guardian.Plug.current_resource(conn)
    profiles = Auth.get_user!(

    render(conn, "profiles.json", profiles: profiles)

Yes, sorry, I edited my answer above. As you are rendering JSON, the layout is set to false by default.

You are still using plural when it should be singular.

The catch clause should be at the end if You want to catch match error.

Well, profiles is not a list, but a User.

1 Like

Yes I know. The reason I’ve put there because I’m getting error when I put in the end. So I wanted to know what data I’m getting in my assigns.

Plural thing yes I know. I wanted to check if somehow the map I’m getting can be define in another view. Sorry if I’m not making sense

You should also show the controller, and tell which action You are rendering…

Here is controller

Well, profiles is just a single User, as told, but You try to…

And this won’t work.

Yes. I already resolved that. Mainly I was confused about that Layout: false part