Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error at phoenix.gen.json #1232

Closed
rhazdon opened this issue Sep 26, 2015 · 2 comments
Closed

Compilation error at phoenix.gen.json #1232

rhazdon opened this issue Sep 26, 2015 · 2 comments

Comments

@rhazdon
Copy link

rhazdon commented Sep 26, 2015

Hi guys,

I tried to generate a JSON resource with the command line

$ mix phoenix.gen.json

My example:

$ mix phoenix.gen.json User users for_name:string last_name:string

After that I want to update the database via

mix ecto.migrate

The following error occurs:

MyMac:rest_api user$ mix ecto.migrate
Compiled web/views/changeset_view.ex
Compiled web/views/user_view.ex
Compiled web/models/user.ex

== Compilation error on file web/controllers/user_controller.ex ==
** (CompileError) web/controllers/user_controller.ex:20: function user_path/3 undefined
    (stdlib) lists.erl:1337: :lists.foreach/2
    (stdlib) erl_eval.erl:669: :erl_eval.do_apply/6
    (elixir) lib/kernel/parallel_compiler.ex:97: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/8

It seems phoenix generates a function that does not exist.

The malfunction in user_controller.ex. The line between the *** *** is the affected line:

def create(conn, %{"user" => user_params}) do
    changeset = User.changeset(%User{}, user_params)

    case Repo.insert(changeset) do
      {:ok, user} ->
        conn
        |> put_status(:created)
   ***  |> put_resp_header("location", user_path(conn, :show, user)) ***
        |> render("show.json", user: user)
      {:error, changeset} ->
        conn
        |> put_status(:unprocessable_entity)
        |> render(RestApi.ChangesetView, "error.json", changeset: changeset)
    end
  end

Thank you for your help!

@chrismccord
Copy link
Member

After you ran the command, the first thing the output told you to do was to add resources "/users", UserController to a scope in your router. It looks like you missed that step :)

@rhazdon
Copy link
Author

rhazdon commented Sep 26, 2015

Shame on me... thank you... you're absolutely right... :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants