I'm new to Elixir/Phoenix and I was wondering if there was a way to essentially require IEx
for the purpose of IEx.pry
in the same manner that in Ruby/Rails you can add something like
group :test, :development do
gem 'pry', require: 'pry'
end
which would allow you to binding.pry
in essentially any file without needing to include require 'pry'
I'm finding that having to require IEx
on any controller, model, view, etc I want to debug to be tedious.
Some of the things may be different or may not even work if you are using a different version of IEx. You can launch IEx shell from the command line simply typing iex or if you want to launch a phoenix project by typing iex -S mix phx.server or typing iex -S mix while in a mix based Elixir project.
To run your tests in an Elixir or Phoenix project in the Elixir Interactive shell run: To run your Phoenix app in the Elixir Interactive shell, you can run: IEx.pry () allows you to set a breakpoint in your code and inspect values.
You can launch IEx shell from the command line simply typing iex or if you want to launch a phoenix project by typing iex -S mix phx.server or typing iex -S mix while in a mix based Elixir project. Throughout the article, I will show output from real iex session but in most cases output will be truncated and annotated to suit this article.
However, using an actual debugger with a visual interface is much more convenient when you want to view multiple locations, step through the code, and monitor data as your application runs. Setting up the debugger for phoenix or elixir is done automatically for you by Visual Studio Code.
You can use web/web.ex
file.
A module that keeps using definitions for controllers, views and so on.
This can be used in your application as:
use App.Web, :controller use App.Web, :view
The definitions below will be executed for every view, controller, etc, so keep them short and clean, focused on imports, uses and aliases.
Just put require IEx
here when you need it for controllers, models etc.
defmodule App.Web do
def model do
quote do
...
require IEx
end
end
def controller do
quote do
...
require IEx
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With