2
votes

I wanted to debug Controllers in Phoenix the way i used to do with Rails by simply putting binding.pry at any place i want to put a break point, So, i tried the same thing with Phoenix using IEx.pry like below:-

defmodule Rumbl.UserController do
  use Rumbl.Web, :controller
  require IEx

  def index(conn, _params) do
    IEx.pry
    users = Repo.all(Rumbl.User)
    render conn, "index.html", users: users
  end
end

But it's not putting any break point instead it's giving this message on console.

Cannot pry #PID<0.352.0> at web/controllers/users_controller.ex:6. Is an IEx shell running?

I also, tried running Iex shell by doing iex -S mix but problem still continues. Did, i miss something or I am doing something wrong?

2
What error do you get with iex -S mix? Did you pass phoenix.server as an argument too? Try with iex -S mix phoenix.server.Dogbert
1. Stop current server. 2. Start server with iex -S mix phoenix.server. Are the results exactly the same?coderVishal
ohh So, phoenix server itself has to run from IEx shell. Got it and it worked fine now. Thanks!!Subhash Chandra

2 Answers

3
votes

Even I ran into this issue. Try this

  • Stop current server.
  • Start server with iex -S mix phoenix.server
0
votes

In case anyone is following an old tutorial - following up on coderVishal's answer,

  • Stop the running server
  • Start the server with iex -S mix phx.server