skanel

skanel

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

Showing Posts 1 to 7

OvermindDL1

OvermindDL1

Are you on Ecto 2.1+?

kokolegorille

kokolegorille

You should update phoenix to 1.3.0, not the release candidate

skanel

skanel OP

Oh I see I am using Ecto V2.2

skanel

skanel OP

still the same error

kokolegorille

kokolegorille

I have the same error doing the same command… so it must be ~D[2017-09-01] not seen as a date.

iex> ~D[2017-09-01] |>  Ecto.Date.to_string
** (FunctionClauseError) no function clause matching in Ecto.Date.to_string/1    
    
    The following arguments were given to Ecto.Date.to_string/1:
    
        # 1
        ~D[2017-09-01]
    
    Attempted function clauses (showing 1 out of 1):
    
        def to_string(%Ecto.Date{year: year, month: month, day: day})
    
    (ecto) lib/ecto/date_time.ex:193: Ecto.Date.to_string/1
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.

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

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews