wernerlaude
Json View problem - Could not render / please define a matching clause for render/2 or define a template
I try to render a view as json.
router:
pipeline :api do
plug :accepts, ["json"]
end
scope "/api", MyAppWeb do
pipe_through :api
get "/networking", PageController, :networking
end
controller:
def networking(conn, _params) do
q = from m in Meeting, where: m.is_active == true
meetings = Repo.all(q)
render(conn, "networking.json", meetings: meetings)
end
view:
def render("networking.json", %{meetings: meetings}) do
%{data: render_many(meetings, PageView, "networking.json")}
end
def render("networking.json", %{meeting: meeting}) do
%{id: meeting.id,
title: meeting.title}
end
But I get: Could not render "networking.json for MyAppWeb.PageView, please define a matching clause for render/2 or define a template…
Did I forget something? Thanks for support.
Most Liked
pureyoda
def render("networking.json", %{meetings: meetings}) do
%{data: render_many(meetings, PageView, "networking.json")}
end
def render("networking.json", %{meeting: meeting}) do
%{id: meeting.id,
title: meeting.title}
end
The root key of the second parameter of the function below must match the view’s name.
views/page_view.ex
def render(“networking.json”, %{page: meeting}) do
2
acrolink
I guess the problemscan be solved like this:
def render("index.json", %{meetings: meetings}) do
%{data: render_many(meetings, PageView, "networking.json")}
end
def render("networking.json", %{meeting: meeting}) do
%{id: meeting.id,
title: meeting.title}
end
and in controller:
render(conn, "index.json", meetings: meetings)
1
kokolegorille
The plug is here as it is defined in the router in the OP.
I would try to add a catch all clause in the view, just to see what params are sent. Like so…
def render("networking.json", params) do
IO.inspect params
end
1
Popular in Questions
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
lets say i have a sample like
a = 20; b = 10;
if (a > b) do
{:ok, "a"}
end
if (a < b) do
{:ok, b}
end
if (a == b) do
{:ok, "equa...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
I have VueJS GUIs with the project generated using Webpack.
I have Elixir modules that will need to be used by the VueJS GUIs.
I forese...
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
I would like to know what is the best IDE for elixir development?
New
Other popular topics
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something…
Haskell reminds me of Java, and e...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









