Last active
December 20, 2019 08:15
-
-
Save palmo25/38e2c82b71e9eebfd768dd4f808b8fb5 to your computer and use it in GitHub Desktop.
nested routes and routes helper path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#routes | |
resources "/projects", ProjectController do | |
resources "/budgets", BudgetController | |
end | |
#budget_view.ex | |
defmodule ProjexWeb.ProjectView do | |
use ProjexWeb, :view | |
end | |
#budget_view.ex | |
defmodule ProjexWeb.BudgetView do | |
use ProjexWeb, :view | |
end | |
# project_controller.ex | |
... | |
def show(conn, %{"id" => id})do | |
project = Programs.get_project!(id) | |
budget = Programs.get_budget!(id) | |
render(conn, "show.html", project: project, budget: budget) | |
end | |
... | |
# budget_controller.ex | |
... | |
def show(conn, %{"project_id" => project_id, "id" => id}) do | |
project = Programs.get_project!(project_id) | |
render(conn, "show.html", project: project, budget: id) | |
end | |
... | |
# budget/show.html.eex | |
<h2>Show Budget</h2> | |
<%= @project.name %> | |
<%= @budget %> | |
#project/show.html.eex | |
<h2>Scheda progetto</h2> | |
<p><strong>Titolo progetto:</strong> <%= @project.name %></p> | |
<p><strong>Breve descrizione:</strong><%= @project.description %></p> | |
<p><strong>Inizio progetto:</strong><%= @project.start_date %></p> | |
<p><strong>Fine progetto:</strong><%= @project.end_date %></p> | |
<%= link "show", to: Routes.project_budget_path(@conn, :show, @project, @budget) %> #This line is causing troubles | |
# THIS IS THE ERROR | |
ArgumentError at GET /projects/1 | |
assign @budget not available in eex template. | |
Please make sure all proper assigns have been set. If this | |
is a child template, ensure assigns are given explicitly by | |
the parent template as they are not automatically forwarded. | |
Available assigns: [:conn, :project, :view_module, :view_template] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment