Can someone tell me how I can get
Identify an ID, get the name of another table.
I currently have my “form” this way.
Daily availability media
<table class="table">
<thead>
<tr>
<th>Local</th>
<th>Disponib</th>
<th>Date</th>
<th></th>
</tr>
</thead>
<tbody>
<%= for disp <- @disps do %>
<tr>
<td><%= disp.city_id %></td>
<td><%= disp.disponib %></td>
<td><%= disp.date %></td>
<td class="text-right">
<!-- <%= link "Show", to: disp_path(@conn, :show, disp), class: "btn btn-default btn-xs" %>
<%= link "Edit", to: disp_path(@conn, :edit, disp), class: "btn btn-default btn-xs" %>
<%= link "Delete", to: disp_path(@conn, :delete, disp), method: :delete, data: [confirm: "Delete?"], class: "btn btn-danger btn-xs" %> -->
</td>
</tr>
<% end %>
</tbody>
</table>
<%= link "New availability", to: disp_path(@conn, :new) %>
model 1 > disp.ex
defmodule Relat.Disp do
use Relat.Web, :model
schema "disps" do
field :disponib, :float
field :date, Ecto.Date
belongs_to :city, Relat.City
timestamps()
end
@doc """
Builds a changeset based on the `struct` and `params`.
"""
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:disponib, :date, :city_id])
|> validate_required([:disponib, :date, :city_id])
end
end
Model 2 > local.ex
defmodule Relat.Local do
use Relat.Web, :model
schema "locais" do
field :city, :string
timestamps()
end
@doc """
Builds a changeset based on the `struct` and `params`.
"""
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:city])
|> validate_required([:city])
end
end
Currently my index.html.eex