ankane / ahoy_email

First-party email analytics for Rails
MIT License
1.11k stars 137 forks source link

Route for tracking opens, is different than the one rendered in the template #129

Closed bo-oz closed 5 years ago

bo-oz commented 5 years ago

Hi,

The open tracking pixel is rendered like /messages/SomeKindOfToken/open.gif, while the actual route that seems to be created by default in my app is: /ahoy/messages/SomeKindOfToken/open/gif. Is this a bug, or should I configure it differently somehow?

Thanks.

ankane commented 5 years ago

Hey @bo-oz, are you able to reproduce with a fresh app?

ship-happens commented 5 years ago

This happens when AhoyEmail.api = true hasn't been set in an initializer. I assumed the value was for the purpose of setting up endpoints which respond to the generated URLs (which in my case happens in a separate application), but evidently it also plays a role in how to generate that URL.

ankane commented 5 years ago

Thanks for the update @maxxsnake. That makes sense, since there's no way to know the path if the engine isn't mounted. I'm surprised Rails doesn't throw an error in this situation. Ahoy Email could throw an error, but after a quick search, I'm not sure there's a good way to tell if a Rails engine is mounted.

Related: https://github.com/rails/rails/issues/4940