Search code examples
ruby-on-railsruby-on-rails-3

Rails mailer views in separated directory


I have small organizatoric issue, in my application I have 3 mailer User_mailer, prduct_mailer, some_other_mailer and all of them store their views in app/views/user_mailer ...

I will want to have a subdirectory in /app/views/ called mailers and put all in the folders user_mailer, product_mailer and some_other_mailer.

Thanks,


Solution

  • I so agree with this organization strategy!

    And from Nobita's example, I achieved it by doing:

    class UserMailer < ActionMailer::Base
      default :from => "[email protected]"
      default :template_path => '**your_path**'
    
      def whatever_email(user)
        @user = user
        @url  = "http://whatever.com"
        mail(:to => user.email,
             :subject => "Welcome to Whatever",
             )
      end
    end
    

    It is Mailer-specific but not too bad!