从控制器访问 stylesheet_link_tag

发布于 2024-12-27 00:11:14 字数 167 浏览 2 评论 0原文

是否有从控制器调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扶醉桌前 2025-01-03 00:11:14

您应该能够使用它从控制器访问样式表:

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")

和影子一齐双人舞 2025-01-03 00:11:14

这个问题与这个问题密切相关:
一个引用如何从 Rails 3.1 中的控制器编译资源?

请参阅我的答案,但是,更简单地说,您可以访问由 Sockets 库管理的 Rails 资源管道,从Rails.application.assets。这将是一个 Sprockets::Environment 实例,记录在 Sprockets 项目 。你可以这样使用它:

Rails.application.assets['application.css'].pathname  #=> "/home/username/project..."
Rails.application.assets['application.css'].to_s  #=> "html, body { ..."

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 { ..."
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文