crisefd

crisefd

Can't find init/1 function because controller is unavailable

I’m building my first app in Phoenix. And I keep seeing this warning all the time in my router.ex file:

warning: function DummyApiWeb.CommentController.init/1 is undefined (module DummyApiWeb.CommentController is not available)
  lib/ldummy_api_web/router.ex:2

This is my router.ex :

defmodule DummyApiWeb.Router do
  use DummyApiWeb, :router

  pipeline :api do
    plug :accepts, ["json"]
  end

  scope "/api/v1", DummyApiWeb do
    pipe_through :api
    resources "/users", UserController
    resources "/clubs", ClubController do
      resources "/items", ItemController do
        resources "/comments", CommentController, only: [:create]
      end
    end

  end

  pipeline :browser do
    plug :accepts, ["html"]
  end

  scope "/", DummyApiWeb do
    pipe_through :browser
    get "/", DefaultController, :index
  end

end

And my comment_controller.ex:

defmodule DummyApi.CommentController do
  use DummyApiWeb, :controller

  def create(conn, %{"item_id" => item_id, "user_id" => user_id, "comment" => comment_params}) do
    ...

  end

end

Marked As Solved

kokolegorille

kokolegorille

You defined

DummyApi.CommentController

But probably wanted

DummyApiWeb.CommentController

Also Liked

crisefd

crisefd

:man_facepalming: That’s correct

Where Next?

Popular in Questions Top

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
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
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 131117 1222
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54260 488
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
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
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

We're in Beta

About us Mission Statement