29

Rails has 607 open issues...so, rather than plugging that hole even more I though Id try here first. I have upgraded to 4.1 and am implementing rails mailer previews. I tried upgrading my existing mailer and adding tests/mailers/previews directory. When that gave the following error I tried generating a new mailer. Same error.

 class NotifierPreview < ActionMailer::Preview
    def welcome
      Notifier.welcome(User.first)
    end
  end

results in this error:

 The action 'notifier' could not be found for Rails::MailersController

I've tried searching google, the docs, stack overflow, but nothing eludes to this error.

Anyone experience this or have any ideas?

hellion
  • 4,602
  • 6
  • 38
  • 77

4 Answers4

82

The default preview path is /test/mailers/previews but rspec will override this to be /spec/mailers/previews

You can set the path to be whatever you like with:

config.action_mailer.preview_path = "#{Rails.root}/test/mailers/previews"
Calvin
  • 1,056
  • 8
  • 5
  • 11
    My hero! Mailer previews suddenly stopped working- just got a blank/white page instead of the index. Didn't realize rspec screwed with my mailer paths. – Rockster160 Apr 14 '16 at 15:47
7

This is because you are using UserMailer with NotifierPreview. Change NotifierPreview to UserMailerPreview and it will start working. Check the example implementation https://github.com/RichIsOnRails/ActionMailerPreviewsExample and tutorial.

Cheers!!

maximus ツ
  • 7,949
  • 3
  • 25
  • 54
  • I wish it were that simple...but, my naming is correct. – hellion Jun 22 '14 at 02:05
  • Did you check the example git repo? it uses Rails 4.1. – maximus ツ Jun 22 '14 at 09:06
  • 1
    Turns out the prob (so it seems) is in my routes file. I have two routes "get '/:controller(/:action(/:id))', get '/:controller(/:action(/:id))(.:format)'" that are evidently deprecated...or will be soon. This is via a comment in the rails issue I submitted. When I remove these routes I get other errors...at least now I know the root cause. I'm using the link you shared to help get things fixed up. Thanks, Maximus! – hellion Jun 22 '14 at 16:21
6

If you're using rspec, make sure that the rspec-rails gem is being loaded in the development environment, otherwise Rails will look for the previews under the /test folder, not /spec.

Samuel
  • 2,331
  • 1
  • 22
  • 40
4

Remove the line(s)

get '/:controller(/:action(/:id))'
get '/:controller(/:action(/:id))(.:format)'

from your routes.rb

As @hellion says in a comment on the previous answer this is the solution to this problem.

LpLrich
  • 2,463
  • 2
  • 20
  • 31
  • 2
    I was unable to remove the catch all routes from my app, so this was helpful http://stackoverflow.com/questions/26130130/what-are-the-routes-i-need-to-set-up-to-preview-emails-using-rails-4-1-actionmai – Derek Hall Jul 17 '15 at 19:12