vt-elixir / ja_resource

A behaviour to reduce boilerplate code in your JSON-API compliant Phoenix controllers without sacrificing flexibility.
Other
113 stars 33 forks source link

serialization_opts/3 results in no function clause matching in Keyword.get/3 #43

Closed joshuataylor closed 7 years ago

joshuataylor commented 7 years ago

So doing something like:

def serialization_opts(_conn, _params, models) do
  %{
    meta: %{
      current_page: models.page_number,
      page_size: models.page_size,
      total_pages: models.total_pages,
      total_records: models.total_entries
    }
  }
end

In my phoenix control results in:

    ** (FunctionClauseError) no function clause matching in Keyword.get/3
        (elixir) lib/keyword.ex:150: Keyword.get(%{meta: %{current_page: 1, page_size: 20, total_pages: 2, total_records: 26}, page: %{last: "/api/foo?page[page]=2&page[page-size]=20", next: "/api/foo?page[page]=2&page[page-size]=20", self: "/api/foo?page[page]=1&page[page-size]=20"}}, :include, [])
        lib/ja_serializer/builder/top_level.ex:25: JaSerializer.Builder.TopLevel.build/1
        lib/ja_serializer.ex:59: JaSerializer.format/4
        (phoenix) lib/phoenix/view.ex:335: Phoenix.View.render_to_iodata/3
        (phoenix) lib/phoenix/controller.ex:642: Phoenix.Controller.do_render/4
        (ja_resource) lib/ja_resource/plug.ex:61: JaResource.Plug.call/2
joshuataylor commented 7 years ago

It's meant to be a list, I'll open a PR.