woohaaha

woohaaha

Accessing routes in the domain layer without including MyAppWeb in MyApp context

Hi all,

I am sending lifecycle emails from my the MyApp context. I’m using Bamboo.Template like so:

defmodule MyApp.Notifications do
  use Bamboo.Template, view: MyApp.Notifications.Views.EmailView

  def welcome(many-params) do
    base_email()
      |> to(email)
      |> subject("Welcome")
      |> assign(:user, user)
      |> put_text_layout({MyApp.Notifications.Views.EmailView, "welcome.text"})
      |> put_text_layout({MyApp.Notifications.Views.EmailView, "welcome.html"})
      |> render(:welcome)
      |> Mailer.deliver_later()
  end
end

The benefit of Bamboo.Template is that I don’t have to include Phoenix web layer concerns or MyAppWeb in the context.

In the welcome.html.eex email I would like to include a url like a verify_email_url or a referral_url.

How do I get the needed url paths, specified in the Router (which is in Web), into my context layer?

Thank you

Most Liked

a8t

a8t

I think you should use the path helpers. I know that it feels like it’s breaking the boundary, but the web concern truly is a dependency for this email, no?

davemenninger

davemenninger

Fwiw, this is what I have done too. I just go ahead and use

MyAppWeb.Router.Helpers.some_url(...)

right in MyApp.Email.

bit4bit

bit4bit

hi, may this help towards maintainable elixir the core and the interface section Activation mail using UrlProvider

woohaaha

woohaaha

Thank you for your reply.

but the web concern truly is a dependency for this email, no?

I feel like it’s not that there’s a web concern that’s a dependency, but that there is a dependency IN the web layer that I’d like access to. Perhaps I’m over thinking this but it seems like routes are just strings. They only get meaning and behavior when looked at from a web browser’s perspective. Otherwise, they’re just strings in a certain shape. But yeah, perhaps over thinking.

Looks like I’ll include MyApp web and just finish the feature :sweat_smile:

kelvinst

kelvinst

You could always send the url as a parameter to the email logic.

Where Next?

Popular in Questions Top

JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
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
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
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
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement