Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails engine mailer missing template

so I am working on a rails engine and generated a mailer which put my views in

app/
  views/ 
    my_engine/ 
      user_mailer/
        account_activation.html.erb
        account_activation.text.erb

to configure the dummy app to display the previews i added

test/dummy/config/environments/development.rb

config.action_mailer.preview_path = MSearcher::Engine.root.join('test/mailers')

test/mailers/previews/my_engine/user_mailer_preview.rb

module MyEngine
    class UserMailerPreview < ActionMailer::Preview
        def account_activation
            User.first
            UserMailer.account_activation(user)
        end
    end
end

now if I create my mailer

/app/mailers/my_engine/user_mailer

module MyEngine
    class UserMailer < Application Mailer
        def account_activation(user)
            mail to: user.email, subject: "Account Activation"
        end
    end
end

with this i can navigate to localhost:3000/rails/mailers/my_engine/users_mailer/account_activation

where I get the error

Template is missing
Missing template layouts/mailer with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :coffee]}. 
Searched in: * 
    "/home/me/workspace/rails/my_engine/test/dummy/app/views" * 
    "/home/me/workspace/rails/my_engine/app/views"

so the default behavior is looking for my templates in the folder above the one that it should be. How can I configure the proper behavior?

like image 839
mkrinblk Avatar asked Sep 02 '25 07:09

mkrinblk


1 Answers

What I ended up doing was telling it where it could find a layout

When I generated my mailer it created a default layout in

app/
  views/ 
    layouts
      my_engine/
        mailer.html.erb
        mailer.text.erb
    my_engine/ 
      user_mailer/
        account_activation.html.erb
        account_activation.text.erb

however the default template in app/mailers/my_engine/application_mailer.rb

module MyEngine
  class ApplicationMailer < ActionMailer::Base
    default from: '[email protected]'
    layout 'mailer'
  end
end

This layout really should be 'my_engine/mailer' I don't know why Rails doesn't do this automatically but that solved the problem for me.

like image 55
mkrinblk Avatar answered Sep 04 '25 22:09

mkrinblk