Search code examples
ruby-on-railsactionmailerpreview

rails email preview / Policy directive: "style-src 'unsafe-inline'"


Getting the following when using rails built in email previews :

    Refused to load the stylesheet
   'http://app.lvh.me:3000/packs/...' because it violates
    the following Content Security
    Policy directive: "style-src 'unsafe-inline'".

Ended up adding the following in headers :

meta http-equiv="Content-Security-Policy"
     content="default-src *; style-src 'self' http://* 'unsafe-inline'; script-src 'self' http://* 'unsafe-inline' 'unsafe-eval';"

But still getting the issue

Does anyone encountered and solved this issue ?


Solution

  • Obviously, this answer could be enhanced by explaining why such happened, but so far it seems that the workaround is to add the following gem :

    gem 'premailer-rails'
    

    As explained here.