aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/rails
diff options
context:
space:
mode:
authorPrathamesh Sonpatki <csonpatki@gmail.com>2016-03-12 09:01:06 +0530
committerPrathamesh Sonpatki <csonpatki@gmail.com>2016-03-12 09:40:54 +0530
commit4d0bf49b92a77542185644660f2c9cec98e66de5 (patch)
tree07f675ca68ad9a3d5ad379e721c7006ae9acf955 /actionmailer/lib/rails
parent9201030320d09bb2ec76a7cc59aa58f77f984995 (diff)
downloadrails-4d0bf49b92a77542185644660f2c9cec98e66de5.tar.gz
rails-4d0bf49b92a77542185644660f2c9cec98e66de5.tar.bz2
rails-4d0bf49b92a77542185644660f2c9cec98e66de5.zip
Correctly generate application_mailer.rb in mountable engines
- Followup of https://github.com/rails/rails/pull/24161.
Diffstat (limited to 'actionmailer/lib/rails')
-rw-r--r--actionmailer/lib/rails/generators/mailer/mailer_generator.rb13
-rw-r--r--actionmailer/lib/rails/generators/mailer/templates/application_mailer.rb2
2 files changed, 13 insertions, 2 deletions
diff --git a/actionmailer/lib/rails/generators/mailer/mailer_generator.rb b/actionmailer/lib/rails/generators/mailer/mailer_generator.rb
index f86d43be61..01bdfb0685 100644
--- a/actionmailer/lib/rails/generators/mailer/mailer_generator.rb
+++ b/actionmailer/lib/rails/generators/mailer/mailer_generator.rb
@@ -11,8 +11,8 @@ module Rails
template "mailer.rb", File.join('app/mailers', class_path, "#{file_name}_mailer.rb")
in_root do
- if self.behavior == :invoke && !File.exist?('app/mailers/application_mailer.rb')
- template 'application_mailer.rb', 'app/mailers/application_mailer.rb'
+ if self.behavior == :invoke && !File.exist?(application_mailer_file_name)
+ template 'application_mailer.rb', application_mailer_file_name
end
end
end
@@ -23,6 +23,15 @@ module Rails
def file_name
@_file_name ||= super.gsub(/_mailer/i, '')
end
+
+ private
+ def application_mailer_file_name
+ @_application_mailer_file_name ||= if mountable_engine?
+ "app/mailers/#{namespaced_path}/application_mailer.rb"
+ else
+ "app/mailers/application_mailer.rb"
+ end
+ end
end
end
end
diff --git a/actionmailer/lib/rails/generators/mailer/templates/application_mailer.rb b/actionmailer/lib/rails/generators/mailer/templates/application_mailer.rb
index 02e8d3e454..93fd9a7449 100644
--- a/actionmailer/lib/rails/generators/mailer/templates/application_mailer.rb
+++ b/actionmailer/lib/rails/generators/mailer/templates/application_mailer.rb
@@ -1,4 +1,6 @@
+<% module_namespacing do %>
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout :mailer
end
+<% end %>