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

Support for subdomain in mailer generated urls #778

Open
adonespitogo opened this issue Nov 28, 2018 · 5 comments
Open

Support for subdomain in mailer generated urls #778

adonespitogo opened this issue Nov 28, 2018 · 5 comments

Comments

@adonespitogo
Copy link

I use thredded for my app and mounted thredded as:

constraints subdomain: "forum" do
  mount Thredded::Engine => '/' as: 'forum'
end

Works fine exept the urls in mails points to main host and results to 404 error

Temporary work around is to create routes that redirect those requests manually to subdoman: "forum"

@adonespitogo
Copy link
Author

Thanks. I'll try this out once I got home from vacation and will report back. Happy holidays!

@rickychilcott
Copy link
Contributor

Did this ever get resolved?

@glebm
Copy link
Collaborator

glebm commented Apr 19, 2020

The mailer uses standard Rails stuff to generate URLs, so I'd imagine the original poster didn't have the right configuration

@rickychilcott
Copy link
Contributor

rickychilcott commented Apr 19, 2020

Thanks for your quick response. I agree that it should be fixed, but I'm running into this myself with a similar setup. This rails issue appears to never have been fixed but it explains it way better than I could. rails/rails#34252

The fix that I'm thinking I can hack together is set the threaded mailers to inherit from my own ThreddedMailer and then in a before_action to set the default_url_options to include the correct options. It's a bit brittle but should work.

The other option would be to change all mailer url_generation steps to make a custom router object that would default to the engine's routes, but would optionally allow you to override with custom behavior.

Thoughts @glebm?

@rickychilcott
Copy link
Contributor

the first solution I came up with worked and was fairly straightforward.

# in config/initializers/thredded.rb
Thredded.parent_mailer = "ThreddedMailer"

# in app/mailers/thredded_mailer.rb
class ThreddedMailer < ActionMailer::Base
  around_action :configure_default_url_options

  def configure_default_url_options
    original_default_url_options = self.default_url_options.dup # assumes we already have a host set
    self.default_url_options[:host] = ["discussion.", self.default_url_options[:host]].join

    yield

    self.default_url_options = original_default_url_options
  end
end

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

No branches or pull requests

3 participants