Is there a was to call stylesheet_link_tag
from the controller? I am creating a PDF file in memory and passing it along to an api call to another service. I am using PDFKit and it requires me to send the style sheet link to it. I am using Rails 3.1 and therefore need access to the asset pipeline through this method.
Thanks for the help!
You should be able to use this to access the stylesheet from your controller:
ActionController::Base.helpers.asset_path("stylesheet_i_want.css")
This question is closely related to this one:
How does one reference compiled assets from the controller in Rails 3.1?
See my answer there, but, more briefly, you can access the Rails asset pipeline, which is managed by the Sockets library, from Rails.application.assets
. That will be a Sprockets::Environment
instance, documented at the Sprockets project. You can use it like this:
Rails.application.assets['application.css'].pathname #=> "/home/username/project..."
Rails.application.assets['application.css'].to_s #=> "html, body { ..."