Ho questo modello,date_select in forma non riesce con "<field> non è valido"
<div class="form-group">
<label>Insurance Expiry : </label>
<%= date_select f, :insurance_expiry, class: "form-control" %>
</div>
e la migrazione ha,
def change do
create table(:buses) do
# snipped
add :insurance_expiry, :date, default: Ecto.Date.local
end
e nel modello di db,
schema "buses" do
# snipped
field :insurance_expiry, :date
end
informazioni di debug su crea azione,
[info] Processing by BusMan.BusController.create/2
Parameters: %{"_csrf_token" => "PDkIZycHTRJsEzwOEBJRXxo6MVIFJgAAHla/FI4Y5PQxTYdk/XakNg==", "_utf8" => "✓", "bus" => %{"bus_no" => "138", "chassis_no" => "nTHSNTH", "engine_no" => "RCHR989", "insurance_expiry" => %{"day" => "1", "month" => "10", "year" => "2019"}, "models" => "NTHRCG898", "reg_no" => "TN21W0613", "year_of_registration" => "1990"}, "format" => "html"}
modulo di presentazione viene a mancare con:
Oops, something went wrong! Please check the errors below:
Insurance expiry is invalid
voglio solo inserire una data, Is date_select
è quello che mi serve o mi sto perdendo qualcosa di diverso?
'insurance_expiry_map = bus_params [ "insurance_expiry"] {: ok, insurance_expiry_date} = Ecto.Date.cast (insurance_expiry_map) updated_bus_params =% {bus_params | "insurance_expiry" => insurance_expiry_date} changeset = Bus.changeset (% Bus {}, updated_bus_params) ' Ho anche cambiato il tipo': date' in personalizzato 'Ecto.Date' nello schema. Questo ha funzionato :) – Shanthakumar
Non è necessario eseguire il cast esplicito. L'errore è stato il fatto che hai usato ': date' e non' Ecto.Date'. Alzerò presto errori migliori per questo. –