0

I would like to reuse my partials in mailer layouts, but I want to avoid rendering the hyperlinks and instead print out just their name, like using link_to_if / link_to_unless methods.
Which condition could I check to prevent the rendering all the links inside mailer layouts?

Claudio Floreani
  • 2,441
  • 28
  • 34

1 Answers1

0

Inside your email view, you can use something like this :

<%= controller.class.name %>

The printed controller name will be a mailer : "ApplicationMailer", ...

You can then Regex or use a string helper ...

Maxence
  • 2,029
  • 4
  • 18
  • 37
  • 1
    That will work, and I've accepted the answer, but this way the links will appear when I preview my emails (the preview method is defined elsewhere). However I found a simpler solution, i.e. to check for the existence of the `@subject` variable, which is always set in Mailer and preview's controllers, so I can just use `link_to_unless @subject, product, edit_product_path(@product)` – Claudio Floreani Oct 30 '22 at 18:10
  • Usually your preview Mailers inherits from `ActionMailer::Preview` and you usually name them `ApplicationMailerPreview` (at least this is how generating the mailer previews with Rspec does). It should be quite easy to filter out also. But glad you found a solution. – Maxence Oct 30 '22 at 19:24