Rails 3 Team to Insert Text of My CSS Styles into the Head of My HTML

Heroku gives the following advice for anyone using HyPDF to convert HTML to PDF:

Place your styles and scripts within <style> and <script> tags instead of loading them using <link> tag.

I am currently using the following:

 = stylesheet_link_tag "print", :media => "print, screen, projection" 

What is the Rails 3.2 code to generate the <style> equivalent with inline unlinked CSS?

(That is, with Rails, it automatically inserts all the CSS from /app/assets/stylesheets/print.scss into the HTML that it generates, instead of manually copying all these CSS into the content_tag and then saving the contents of this tag.)

Could not find anything in the API docs.

Thanks.

0
source share
1 answer

Paste the following code directly into the chapter section of your application. html.erb should work:

 <style> <%= render :file => Rails.application.assets.find_asset('print') %> </style> 

Of course, if you include stylesheets from several different views, instead you want to set up revenue in application.html.erb:

 <style> <%= yield(:inline_style) %> </style> 

Then from each view:

 <% content_for :inline_style %> <%= render :file => Rails.application.assets.find_asset('**stylesheet name**') %> <% end %> 

Or, if you still want to use the asset pipeline, see How to embed css when using the rails resource pipeline

0
source

Source: https://habr.com/ru/post/1484876/


All Articles