Ruby/Sinatra - 提供 css、javascript 或图像文件 [英] Ruby / Sinatra - serving up css, javascript, or image files

查看:29
本文介绍了Ruby/Sinatra - 提供 css、javascript 或图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过 Sinatra 路由您的请求以便它在不处理的情况下提供文件的正确方法是什么?我正在寻找人们在 Sinatra 框架中执行此操作的最常见方式?我通常将所有静态内容放在内容"路径中.

What is the correct way to route your request through Sinatra so that it serves up the file with no processing? I'm looking for the most common way people do this in the Sinatra framework? I normally place all of my static content in a "content" path.

例子:
/内容/css
/content/img
/内容/js

examples:
/content/css
/content/img
/content/js

如何使用通配符提供内容下的所有内容?

How can I use a wildcard to serve up everything under content?

我很惊讶这里没有真实的例子:
http://sinatra-book.gittr.com/

I was surprised there were no real examples of this here:
http://sinatra-book.gittr.com/

推荐答案

Sinatra 和 Rails 对静态内容使用路径 public - 例如,./public/javascripts/.然后,这些路径中的所有文件都将由 Web 服务器(例如 Thin、Passenger)提供服务,但 URL 中不需要 /public(例如 #{my_app_root}/public/javascripts/application.js 可以通过 Web 的 URL http://#{my_domain}/javascripts/application.js 获得.

Sinatra and Rails use the path public for static content - e.g., ./public/javascripts/. All files in these paths would then be served by the web server (e.g. Thin, Passenger), but without the need for /public in the URL (e.g. the file at #{my_app_root}/public/javascripts/application.js would be available via the Web at the URL http://#{my_domain}/javascripts/application.js).

这篇关于Ruby/Sinatra - 提供 css、javascript 或图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆