Friends, I just created a submodule in the controller.
def filter_ecdr(conn, params) do
filter = Structure.list_cdr
|> where([c], fragment("? BETWEEN ? AND ?", c.calldate, params["campo1"], params["campo2"]))
|> order_by([c], desc: c.calldate)
|> Repo.paginate(params)
render(conn, "index.html", filter: filter.entries, filter: filter)
end
How do I, for my template to recognize these variables:
campo1 and campo2?
Ex template:
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-calendar-alt"></i></div>
</div>
<input type="date" class="form-control" id="campo1" placeholder="Data">
</div>
Erro:
== Compilation error in file lib/gcall_web/controllers/ecdr_controller.ex ==
** (Ecto.Query.CompileError) `params["date_start"]` is not a valid query expression. If you want to invoke Access.get/2 in a query, make sure that the module Access is required and that get/2 is a macro
(ecto) expanding macro: Ecto.Query.where/3
(gcall) lib/gcall_web/controllers/ecdr_controller.ex:74: GcallWeb.EcdrController.filter_ecdr/2
(ecto) expanding macro: Ecto.Query.order_by/3
(gcall) lib/gcall_web/controllers/ecdr_controller.ex:75: GcallWeb.EcdrController.filter_ecdr/2
(elixir) expanding macro: Kernel.|>/2
(gcall) lib/gcall_web/controllers/ecdr_controller.ex:76: GcallWeb.EcdrController.filter_ecdr/2
(elixir) lib/kernel/parallel_compiler.ex:208: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6