简体   繁体   English

如何使我的Rails应用针对因错误而无法编译的资产返回500状态?

[英]How can I make my Rails app return a 500 status for assets that do not compile due to an error?

I'd like to be able to write a test to ensure one of my SCSS assets can compile successfully, but it's difficult to do reliably do that by matching the body of the response. 我希望能够编写一个测试来确保我的SCSS资产之一可以成功编译,但是要通过匹配响应主体来可靠地做到这一点是很困难的。 I'd like to simply be able to check the response code when accessing the asset's URL, but it seems my app is returning a successful 200 status code even for assets that compile with errors. 我只希望能够在访问资产的URL时检查响应代码,但是即使对于有错误编译的资产,我的应用似乎也能成功返回200状态代码。 Observe: 观察:

$ curl -i http://domain/assets/my_asset.css

HTTP/1.1 200 OK
Content-Type: text/css;charset=utf-8
Content-Length: 1153

However, my logs clearly state that the asset does not compile OK: 但是,我的日志清楚地表明资产无法编译为OK:

Error compiling asset my_asset.css:
Sass::SyntaxError: Undefined variable: "$var".
Served asset /my_asset.css - 500 Internal Server Error

And the asset body does contain the error message, so I know it's serving up a "bad" asset, but the status code does not reflect that. 而且资产主体确实包含错误消息,因此我知道它正在提供“不良”资产,但是状态代码不能反映这一点。

Is there any way I can make my app return a 500 in this case? 在这种情况下,有什么方法可以使我的应用返回500?

Curl is used to transfer data from or to server. Curl用于从服务器传输数据或向服务器传输数据。 In case there exist previous versions of the same file it just gets the data. 如果存在相同文件的先前版本,则仅获取数据。

In case you want to know the status of the new version of the asset then add unique identity for the created asset or you have to remove the previous one before you create a new compilation (and make sure cache is expired in the server for the same asset). 如果您想知道资产新版本的状态,然后为创建的资产添加唯一标识,或者必须在创建新编译之前删除前一个资产(并确保相同服务器的缓存已过期)资产)。

Hope this helps. 希望这可以帮助。

Regards, HBK 问候,HBK

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何知道Rails应用程序中的Memcache状态? - How can I know about Memcache status in my Rails app? 如何从 SQL 返回错误消息并在我的 rails 应用程序中使用这些错误消息? - How can I return error messages from SQL and use these error messages in my rails app? 如何在Rails 2.3应用程序中使捆绑的gem中的静态资产保持同步? - How do I keep static assets from a bundled gem in-sync in my Rails 2.3 app? 什么是 Rails 资产目录上的 Ruby 以及如何在我的旧应用程序中获取它? - What is the Ruby on Rails assets directory and how do I get it in my old app? 如何从Rails的“查看”页面中的/ app / assets / javascripts文件夹中调用JS脚本? - How can I call upon a JS script in my /app/assets/javascripts folder from a View page in Rails? 如何让Rails 3.1在开发模式下连接资产? - How do I make Rails 3.1 concatenate assets in development mode? 我如何在 Rails 3.1 中需要 /app/assets/javascripts 的子目录 - How do I require subdirectories of /app/assets/javascripts in Rails 3.1 如何让Rails 3资产更快地预编译? - How can I make Rails 3 assets precompile faster? 我似乎无法为Rails应用程序生成迁移,如何克服此错误? - I can't seem to generate a migration for my rails app, how do I get past this error? 在已部署的Rails 4应用程序上发送电子邮件时出现500错误。 我怎么看是什么原因造成的? - 500 error when sending emails on deployed rails 4 app. How do I see whats causing this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM