title: Print css (with variables) to a file
body: <p>I have a service that generates epubs, thus I need to generate a css file to be embedded in the epub.</p>
  
  <p>I created a css view under <code>epub/style.css.erb</code> but since the logic is in the service and not in the controller, it seems there is no way to call <a href="https://apidock.com/rails/ActionController/Base/render_to_string" rel="nofollow noreferrer"><code>render_to_string</code></a>. Actually, the service is wrapped in a sidekiq job, which can be called also from an <code>after_update</code> from the model, so this is of further hindrance to <a href="https://apidock.com/rails/ActionController/Base/render_to_string" rel="nofollow noreferrer"><code>render_to_string</code></a>.</p>
  
  <p>I could create like an <code>EpubController</code> and call the <code>render_to_string</code> method from there. But from my service, located under <code>app/services/epub_export.rb</code>, how do I send parameters to / receive output from the controller? This way it smells like I would break the MVC pattern.</p>
  
  <p>But I also don't like the classical way, e.g.</p>
  
  <pre><code>File.open(@css_path, 'w') do |f|
    f.puts "@charset utf-8;"
    f.puts "/* Styles for GEPUB Sample Book */"
    f.puts "h1"
    f.puts "{"
    f.puts "  text-align: center;"
    f.puts "  color: #0000ff;"
    f.puts "  font-weight: normal;"
    f.puts "  font-family: #{@font_family};"
    f.puts "}"
  end
  </code></pre>
  
  <p>Or is there an alternative to this?</p>