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
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Hi,
is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
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 super simple question about elixir - how would I take a file like this
foo
bar
baz
and output a new file that enumerates th...
New
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Other popular topics
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode.
The solution seems to be, in a hyphena...
New
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help.
Where are they similar?
Where do they differ the m...
New
Hello, how can I check the Phoenix version ?
Thanks !
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
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Got a question about when to concat vs. prepending items to list then reversing to achieve appending.
So i know lists boil down to [1 | ...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
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








