Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating mailer layouts by default, including html and body tags #17646

Merged
merged 2 commits into from
Nov 24, 2014

Conversation

andyjeffries
Copy link
Contributor

This should reduce the spam score in some spam detection engines (and is good practice like having an application.html.erb generated by default).

It uses the same name as the mailer if the mailer ends in ...Mailer (e.g. NotifierMailer will generate an app/views/layouts/notifier_mailer.html.erb layout and no layout line in the app/mailers/notifier_mailer.rb class) but if the mailer doesn't end in ...Mailer, then the layout created is prefixed with mailer_ (to avoid conflicts with other layouts) and a layout :... line is added to the mailer class.

There are tests in there, but I don't use Test::Unit so let me know if you want them reworked/tidied up in some way.

The original pull request was #17606 but the author wanted me to take over adding the layout files, as @dhh requested that they not be dealt with directly in the mailer views.

@@ -69,27 +79,41 @@ def test_check_preview_class_collision
def test_invokes_default_text_template_engine
run_generator
assert_file "app/views/notifier/foo.text.erb" do |view|
assert_match(%r(\sapp/views/notifier/foo\.text\.erb), view)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The files generated don't seem to have the filename in the content of the file, so I removed these from the tests. Let me know if this is wrong, but from calling puts view I couldn't see them in the content.

@andyjeffries
Copy link
Contributor Author

Link from the original PR justifying an engine that does penalise for this :

http://wiki.apache.org/spamassassin/Rules/HTML_MIME_NO_HTML_TAG

@andyjeffries
Copy link
Contributor Author

Found another mailer test that seems to require the name of the template within the view itself (which hasn't been there the whole time).

@dhh
Copy link
Member

dhh commented Nov 19, 2014

I don't think we should have a per-mailer layout by default. I think we should just have one. We don't have a per-controller layout by default either. So layout 'mailer' and app/views/layouts/mailer.html.erb seems to be all we need.

@andyjeffries
Copy link
Contributor Author

I agree with you, that does make more sense. But it does make me think, shall we not go further...?

Generate an application_mailer.rb containing an ApplicationMailer class with a default from address in it (a superclass for all mailers, like ApplicationController is to controllers), generated mailers' descend from that class. Have the implicit default layout for ApplicationMailer be application_mailer.html.erb and generate that layout file, then allow specific mailers to override or false the layout to remove it.

Thoughts?

@dhh
Copy link
Member

dhh commented Nov 21, 2014

Yeah, probably about time we did that. We have an ApplicationMailer in all our apps.

@dhh
Copy link
Member

dhh commented Nov 21, 2014

I'd prefer for this ApplicationMailer to declare layout 'mailer', though. application_mailer reads wrong. Let's just go with layouts/mailer.html.erb for the default.

@andyjeffries
Copy link
Contributor Author

OK fair enough, I'll work on this hopefully at the weekend (if not early next week) and add the commit to the ticket.

I assume I need to squash them before it gets merged, but I need to look in to how to do that with Github's PRs.

@prathamesh-sonpatki
Copy link
Member

@andyjeffries You can squash the commits locally and force push to the this branch again. Github will update the PR properly.

@dhh
Copy link
Member

dhh commented Nov 21, 2014

👍

On Nov 21, 2014, at 3:34 PM, Andy Jeffries notifications@github.com wrote:

OK fair enough, I'll work on this hopefully at the weekend (if not early next week) and add the commit to the ticket.

I assume I need to squash them before it gets merged, but I need to look in to how to do that with Github's PRs.


Reply to this email directly or view it on GitHub.

@andyjeffries andyjeffries force-pushed the html_layout_fix branch 2 times, most recently from 4f7b0c1 to a353d79 Compare November 21, 2014 14:56
@andyjeffries
Copy link
Contributor Author

Thanks @prathamesh-sonpatki , did that and it seems to have worked.

@dhh is it as you'd like it now? Anything else I need to do before it can be merged? Thanks for the help on this so far.

@dhh
Copy link
Member

dhh commented Nov 24, 2014

Looking good, but travis says the build is failing?

@andyjeffries
Copy link
Contributor Author

Yeah, I don't know why. The failures are nothing to do with code I've touched. The builds that test the code I changed pass (the first 4), the failures in the other sections are all around ActiveJob. Are those tests generally stable or a bit flakey?

@@ -8,6 +8,7 @@ class MailerGenerator < NamedBase

def create_mailer_file
template "mailer.rb", File.join('app/mailers', class_path, "#{file_name}.rb")
template "application_mailer.rb", File.join('app/mailers/application_mailer.rb')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem like File.join is required here. 😸

@andyjeffries
Copy link
Contributor Author

Good spot, thanks @tgxworld .

@sgrif
Copy link
Contributor

sgrif commented Nov 24, 2014

Master is failing right now, you can ignore the AJ tests

@sgrif
Copy link
Contributor

sgrif commented Nov 24, 2014

To answer your question, they're generally stable the issue came from a transitive dependency updating.

dhh added a commit that referenced this pull request Nov 24, 2014
Creating mailer layouts by default, including html and body tags
@dhh dhh merged commit 35362fc into rails:master Nov 24, 2014
rafaelfranca added a commit that referenced this pull request Nov 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants