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 { ..."
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top