I have a challenge with flash messages and validation error <%= error_tag f, :patient_name %>
not showing when I submit the form. Below are snippets if the code
app.html.eex
<main role="main">
<p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>
<p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>
<%= render @view_module, @view_template, assigns %>
</main>
appointment_controller.ex
def create(conn, %{"room_id" => room_id, "appointment" => appointment_params}) do
params = Map.merge(appointment_params, %{"room_id" => room_id})
case Appointments.create_appointment(params) do
{:ok, _appointment} ->
conn
|> put_flash(:info, "Appointment Created")
|> redirect(to: MeetNowWeb.Router.Helpers.appointment_path(conn, :new, "room_id"))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
and my new.html.eex
<section class="floaty-mc-floatface">
<div class="logo"></div>
<%= form_for @changeset, MeetNowWeb.Router.Helpers.appointment_path(@conn, :create, @room_id), fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<label class= "white-label">
Display Name: <%= text_input f, :patient_name, class: "black-text-input"%>
<%= error_tag f, :patient_name %>
</label>
<%= submit "Enter" %>
<% end %>
</section>