Mange / roadie-rails

Making HTML emails comfortable for the Rails rockstars
MIT License
363 stars 65 forks source link

Problems with automatic asset precompilation when using SCSS #66

Closed unikitty37 closed 7 years ago

unikitty37 commented 7 years ago

I'm running roadie 3.2.0, roadie-rails 1.1.1 with sass 3.4.22, sass-rails 5.0.6, and rails 5.0.0.1.

I have an email containing <%= stylesheet_link_tag 'email' %>, and a mailer containing include Roadie::Rails::Automatic. The styles are defined in app/assets/email.scss.

When I attempt to preview the mail in development, I get:

Asset was not declared to be precompiled in production.
Add `Rails.application.config.assets.precompile += %w( email.css )` to `config/initializers/assets.rb` and restart your server

If I add the line to assets.rb and restart the server, the styles are correctly displayed — but I don't have to do this each time I add a stylesheet to a regular page, of course, just for emails.

The fact that the error complains about the asset not being declared to be precompiled in production seems a bit odd, considering I'm previewing in development! I had a look through the previous issues, and got the impression this was already fixed, so I'm worried I'm doing something wrong here…

It would be great if there was a solution that was fully automatic and didn't require restarting servers — especially production!

I've also noticed that email.scss is getting included on every page, not just in emails. I'm not sure of the best way to do this short of wrapping the email in a div with an id of 'email' and putting #email at the front of every definition in email.css. There doesn't seem to be a *= unrequire email supported in application.css :)

Is there an example app somewhere showing how to use Roadie? That might help new users a lot.

Mange commented 7 years ago

This might have to do with Sprockets and/or Rails 5. I use neither so I don't know much about how they work nowadays, honestly. I'm forced to use undocumented unstable APIs in most cases, so I wouldn't be surprised if something broke by now. 🙁

If I remember correctly, we have to access the asset sources through an internal API that does live compilation, but we have to be careful so we don't do live compilation in production, so there might be some trouble there. Rails provide no API for getting the asset either in its precompiled form, or live compiled otherwise so we're forced to guess.

It would be great if you could create some example app with this behavior that I can test with and provide me with your Gemfile.lock and sources.

If you manage to find the cause yourself, please let me know about it.

Den sön 16 okt. 2016 10:56John Yeates notifications@github.com skrev:

I'm running roadie 3.2.0, roadie-rails 1.1.1 with sass 3.4.22, sass-rails 5.0.6, and rails 5.0.0.1.

I have an email containing <%= stylesheet_link_tag 'email' %>, and a mailer containing include Roadie::Rails::Automatic. The styles are defined in app/assets/email.scss.

When I attempt to preview the mail in development, I get:

Asset was not declared to be precompiled in production. Add Rails.application.config.assets.precompile += %w( email.css ) to config/initializers/assets.rb and restart your server

If I add the line to assets.rb and restart the server, the styles are correctly displayed — but I don't have to do this each time I add a stylesheet to a regular page, of course, just for emails.

The fact that the error complains about the asset not being declared to be precompiled in production seems a bit odd, considering I'm previewing in development! I had a look through the previous issues, and got the impression this was already fixed, so I'm worried I'm doing something wrong here…

(It would be great if there was a solution that was fully automatic and didn't require restarting servers — especially production!)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Mange/roadie-rails/issues/66, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAGP4Ogn88D0VvhKops8p-Iy3X6yO5xks5q0eafgaJpZM4KX7Gi .

milgner commented 7 years ago

I just stumbled upon another issue with Rails 5: when config.assets.compile is false, Rails.application.assets is always nil, rendering the AssetPipelineProvider unable to function. Also, because of the filename digests, the FilesystemProvider doesn't work either.

Mange commented 7 years ago

You should use the normal asset helpers in your views, so the include tags would use the full file name and the file system provider should find them.

Is that not working for you?

Den tor 16 feb. 2017 11:12Marcus Ilgner notifications@github.com skrev:

I just stumbled upon another issue with Rails 5: when config.assets.compile is false, Rails.application.assets is always nil, rendering the AssetPipelineProvider unable to function. Also, because of the filename digests, the FilesystemProvider doesn't work either.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/Mange/roadie-rails/issues/66#issuecomment-280302959, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAGP9HTdmLWKbPL0IuWrnGSPSRSmlM0ks5rdC8wgaJpZM4KX7Gi .

milgner commented 7 years ago

Unfortunately it didn't. But you're making a good point, it should actually work. Maybe it's related to the problem with the asset host URL. I'll investigate further.

Mange commented 7 years ago

I'll close this for now. Please reopen if you find out more information about this problem