defmodule BookList.User do
use BookList.Web, :model
schema "users" do
field :username, :string
field :email, :string
timestamps()
end
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:username, :email])
|> validate_required([:username, :email])
end
end
My guess is the issue is with how you started IEx. By default it doesn’t load any of your code or start any of your processes. You probably just need to do this in the root of your project.
iex(2)> BookList.User.__info__(:functions)
** (UndefinedFunctionError) function BookList.User.__info__/1 is undefined (module BookList.User is not available)
BookList.User.__info__(:functions)
Given you have lib and web suggests that you created the project with mix phoenix.new. mix phx.new would have created lib/book_list and lib/book_list_web.
Therefore you should be using iex -S mix phoenix.server.
I used mix phx.new --no-brunch --no-html book_list and have lib/book_list and lib/book_list_web. See session below. Can’t figure out what is wrong.
$ iex -S mix phoenix.server
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
mix phoenix.server is deprecated. Use phx.server instead.
[info] Running BookListWeb.Endpoint with Cowboy using http://0.0.0.0:4000
Interactive Elixir (1.6.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> BookList.User.__info__(:functions)
** (UndefinedFunctionError) function BookList.User.__info__/1 is undefined (module BookList.User is not available)
BookList.User.__info__(:functions)
iex(1)> require BookList.Use
** (CompileError) iex:1: module BookList.Use is not loaded and could not be found
Assuming you’re using Phoenix 1.3, try replacing use BookList.Web, :model with use Ecto.Schema and import Ecto.Changeset. But I agree with @peerreynders, the existence of separate web and lib directories suggests that something’s not kosher. Are you sure you’re using 1.3?
Those links discuss the old style generators (phoenix.gen) which are only relevant for existing applications. For new applications only the new style generators (phx.gen) should be used.