Going through problems in the “controller”
How do I insert the result of my “select” into a column in database?
Controller:
def new(conn, _params) do
changeset = Disp.changeset(%Disp{})
render(conn, "new.html", changeset: changeset, cities: Repo.all(from(c in Local, select: {c.city, c.id})))
end
def create(conn, %{"disp" => disp_params}) do
changeset = Disp.changeset(%Disp{}, disp_params)
case Repo.insert(changeset) do
{:ok, disp} ->
conn
|> disp.city_id(@cities) ######################################## << Doubt
|> put_flash(:info, "Availability created successfully.")
|> redirect(to: disp_path(conn, :index))
{:error, changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
How would it be?