skanel

skanel

No function clause matching in Ecto.Date.to_string/1

I am trying to create blog with phoenix for learning purpose , but just follow the tutorial,here Building a Blog with Phoenix - Playing With Fire

but this blog is using the older version of deps, I am on the final step but facing error, anyone please give me some advice and how to fix it .

article_view.ex

defmodule Pxblog.ArticleView do
use Pxblog.Web, :view
use Timex

def list_date_format(date, format_string \ “%B %d, %Y”) do
<< Ecto.Date.to_iso8601(date) <> “T00:00:00Z” >>
|> DateFormat.parse!(“{ISOz}”)
|> DateFormat.format!(format_string, :strftime)
end
end

post_view.ex

defmodule Pxblog.PostView do
  use Pxblog.Web, :view
  use Timex
  def publish_status(true), do: "Published"
  def publish_status(_), do: "Draft"

  def date_format(date), do: date_format date, "%d %b %Y"

    def date_format(date = %Ecto.DateTime{}, format_string) do
      Ecto.DateTime.to_iso8601(date)
      |> date_formatter(format_string)
    end
    def date_format(date = %Ecto.Date{}, format_string) do
      << Ecto.Date.to_iso8601(date) <> "T00:00:00Z" >>
      |> date_formatter(format_string)
    end
    def date_format(_, _format), do: ""

    defp date_formatter(date, format_string) do
      date
      |> DateFormat.parse!("{ISOz}")
      |> DateFormat.format!(format_string, :strftime)
    end

end

mix.exs

defp deps do
[
{:phoenix, “~> 1.3.0-rc”},
{:phoenix_pubsub, “~> 1.0”},
{:phoenix_ecto, “~> 3.2”},
{:postgrex, “>= 0.0.0”},
{:phoenix_html, “~> 2.10”},
{:phoenix_live_reload, “~> 1.0”, only: :dev},
{:gettext, “~> 0.11”},
{:cowboy, “~> 1.0”},
{:earmark, “~> 0.1”},
{:timex, “~> 3.1”} # BUT in tutorial is using 0.19
]
end

My error

Most Liked

kokolegorille

kokolegorille

The blog post is old and use phoenix 1.1.4. Old post might not work with newer phoenix version.

BTW Ecto.Date is deprecated https://hexdocs.pm/ecto/Ecto.Date.html#content

OvermindDL1

OvermindDL1

You cannot use a non-Ecto.Date with it in to_string without casting it first. So ~D[2017-09-01] |> Ecto.Date.cast() |> Ecto.Date.to_string().

Why are you using Ecto.Date anyway? In Ecto if you use the :date type it uses Elixir’s Date instead of Ecto’s date and it works just all around better.

Where Next?

Popular in Questions Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

We're in Beta

About us Mission Statement