从控制器访问 stylesheet_link_tag
是否有从控制器调用 stylesheet_link_tag
的方法?我正在内存中创建一个 PDF 文件,并将其传递给另一个服务的 api 调用。我正在使用 PDFKit,它要求我向其发送样式表链接。我使用的是 Rails 3.1,因此需要通过此方法访问资产管道。
感谢您的帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够使用它从控制器访问样式表:
ActionController::Base.helpers.asset_path("stylesheet_i_want.css")
You should be able to use this to access the stylesheet from your controller:
ActionController::Base.helpers.asset_path("stylesheet_i_want.css")
这个问题与这个问题密切相关:
一个引用如何从 Rails 3.1 中的控制器编译资源?
请参阅我的答案,但是,更简单地说,您可以访问由 Sockets 库管理的 Rails 资源管道,从
Rails.application.assets
。这将是一个Sprockets::Environment
实例,记录在 Sprockets 项目 。你可以这样使用它: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 aSprockets::Environment
instance, documented at the Sprockets project. You can use it like this: