Question

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!

Was it helpful?

Solution

You should be able to use this to access the stylesheet from your controller:

ActionController::Base.helpers.asset_path("stylesheet_i_want.css")

OTHER TIPS

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 { ..."
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top