Pilgrim

Pilgrim

No case clause matching: {1234567890, :graphemes}

I am struggling with the error message no case clause matching: {1234567890, :graphemes}. The following are excepts from my code:

defmodule Agency.Client do
  use Ecto.Schema
  import Ecto.Changeset

  schema "clients" do
    field(:name, :string)
    field(:address, :string)
    field(:contact, :string)
    field(:tel_number, :integer)
    timestamps()
  end

  def changeset(client, params \\ %{}) do
    client
    |> cast(params, [:name, :address, :contact, :tel_number])
    |> validate_required([:name, :address, :contact, :tel_number])
    |> validate_length(:name, min: 3)
    |> validate_length(:address, min: 5)
    |> validate_length(:contact, min: 3)
    |> validate_length(:tel_number, min: 8)
    |> validate_change(:name, &validate/2)
  end
end
defmodule Agency do
  alias Agency.{Client, Role}

  @repo Agency.Repo

  def insert_client(attrs) do
    %Client{}
    |> Client.changeset(attrs)
    |> @repo.insert()
  end
end
defmodule AgencyWeb.ClientController do
  use AgencyWeb, :controller

  def index(conn, _params) do
    clients = Agency.list_clients()
    render(conn, "index.html", clients: clients)
  end

  def new(conn, _params) do
    client = Agency.new_client()
    render(conn, "new.html", client: client)
  end

  def create(conn, %{"client" => client_params}) do
    {:ok, _client} = Agency.insert_client(client_params)
    redirect(conn, to: Routes.client_path(conn, :index))
  end
end

new.html.eex

<h1>New Client</h1>

<%= form_for @client, Routes.client_path(@conn, :create), fn f -> %>
  <%= label f, :name %>
  <%= text_input f, :name %>

  <%= label f, :address %>
  <%= text_input f, :address %>

  <%= label f, :contact %>
  <%= text_input f, :contact %>

  <%= label f, :tel_number, "Tel Number" %>
  <%= telephone_input f, :tel_number %>

  <div>
    <%= submit "Submit" %>
  </div>

<% end %>
Params

client

    %{"address" => "fsdfsdfs", "contact" => "sdfsdfsd", "name" => "sdfsfdsf", "tel_number" => "0123456789"}

I think its got something to do with converting string to integer but isn’t Ecto.Changeset.cast supposed to do that?

Marked As Solved

mudasobwa

mudasobwa

Creator of Cure

Eh. I am pretty sure this is a typo, it should be :string. Also, integer type does not have min: 8 guard, hence the error.

Also Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Please show the full stack trace.

Where Next?

Popular in Questions Top

qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
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
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

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29703 241
New
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
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
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
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
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement