Almog
May 19, 2018, 4:46pm
41
Sweet it’s working, holy shit. I have so much more to learn. It’s failing
def show(conn, %{"id" => id}) do
flux = Magnets.get_flux!(id)
render(conn, "show.html", flux: flux)
end
flux_controller.ex:35: MagnifyWeb.FluxController.show/2
which is this part flux = Magnets.get_flux!(id)
Almog
May 19, 2018, 4:47pm
42
Happing after the create which than renders the single view template via show
idi527
May 19, 2018, 4:48pm
43
Sweet it’s working, holy shit. I have so much more to learn. It’s failing
So is it working or is it failing? I don’t see any mention of :magnets
association in
def show(conn, %{"id" => id}) do
flux = Magnets.get_flux!(id)
render(conn, "show.html", flux: flux)
end
Maybe the problem is in the "show.html.eex"
template. Or maybe check your magnets schema again … Maybe there is a typo? Like :magents
instead of :magnets
judging by
schema Magnify.Magnets.Flux does not have association :magents
Almog
May 19, 2018, 4:51pm
44
Working, amazing thanks for the all help had an issue with the following old code I trying to get working
def get_flux!(id)
do Repo.get!(Flux, id)
|> Repo.preload(:magents)
end
just need to remove |> Repo.preload(:magents)
working with this
def get_flux!(id)
do Repo.get!(Flux, id)
end
idi527
May 19, 2018, 4:51pm
45
There’s a type in Repo.preload
. :magents
instead of :magnets
.
Almog
May 19, 2018, 4:52pm
46
Well do I still need repo preload?
idi527
May 19, 2018, 4:53pm
47
I don’t know, depends on whether you render magnets in the "show.html.eex"
template.
def show(conn, %{"id" => id}) do
flux = Magnets.get_flux!(id)
render(conn, "show.html", flux: flux)
end
Almog
May 19, 2018, 4:53pm
48
Yes I will need to that is my next stop no idea to to reference it
I have this - <%= @flux.description %>
but not sure how you render the magnets
idi527
May 19, 2018, 4:54pm
49
Then, yes, you do need to preload :magnets
:
def get_flux!(id) do
Flux
|> Repo.get!(id)
|> Repo.preload(:magnets)
end
so that you have access to them in the template
<%= @flux.description %>
<%= Enum.map(@flux.magnets, fn magnet -> %>
<p><%= magnet.name %></p>
<% end) %>
1 Like