0

In my Rails 7 app I have the following routes set up:

Rails.application.routes.draw do

  scope 'account/:current_account' do

      resources :clients

  end

end

This will, for example, generate a route like this:

/account/:current_account/clients(.:format)

In my ApplicationController I have url_options set up in order to keep @current_account in every request.

class ApplicationController < ActionController::Base

  def url_options
    {:current_account => @current_account}.merge(super)
  end

end

This works fine throughout the entire app, except in all the mailers.

Whenever I try to trigger an email I am getting this error:

possible unmatched constraints: [:current_account]

How can I get this working with all my Mailers too?

Tintin81
  • 9,821
  • 20
  • 85
  • 178

1 Answers1

0

In the mailer you can use the following:

class ClientMailer < ApplicationMailer

  def welcome_email(client)
    @client = client
    @account = Account.find(params[:current_account])
    mail(to: @client.email, subject: 'Welcome to My Awesome Site')
  end
end

This will pass the current_account to the mailer.

Tibic4
  • 3,709
  • 1
  • 13