Ruby on Rails:奇怪的样式表问题

发布于 2024-09-12 17:04:18 字数 2357 浏览 6 评论 0原文

当我打开一个使用 CSS 的页面时,它会工作一次,但在打开 CSS 并重新保存之前不会再次工作。每次我尝试直接访问我的 CSS 时,它都工作正常。但其他时候,它不起作用,我收到以下服务器输出:

[2010-08-01 12:49:37] ERROR NoMethodError: private method `gsub!' called for #<Class:0x7f6d0639ad80>
    /usr/lib/ruby/1.8/webrick/htmlutils.rb:16:in `escape'
    /usr/lib/ruby/1.8/webrick/httpresponse.rb:232:in `set_error'
    /var/www/rails-blog/vendor/rails/railties/lib/webrick_server.rb:94:in `handle_file'
    /var/www/rails-blog/vendor/rails/railties/lib/webrick_server.rb:73:in `service'
    /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
    /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    /usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
    /var/www/rails-blog/vendor/rails/railties/lib/webrick_server.rb:60:in `dispatch'
    /var/www/rails-blog/vendor/rails/railties/lib/commands/servers/webrick.rb:66
    /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
    /var/www/rails-blog/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in `require'
    /var/www/rails-blog/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
    /var/www/rails-blog/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in `require'
    /var/www/rails-blog/vendor/rails/railties/lib/commands/server.rb:49
    /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
    script/server:3
127.0.0.1 - - [01/Aug/2010:12:49:37 BST] "GET /stylesheets/scaffold.css HTTP/1.1" 500 343
- -> /stylesheets/scaffold.css?1280662371

我用来包含样式表的代码是 <%= stylesheet_link_tag 'scaffold' %>。我已经重新启动了 Ruby 服务器,但没有效果。什么可能导致这个问题?

这是阅读官方指南之一

运行 Mongrel 时不会发生这种情况。

When I open up a page that's using my CSS it will work once, but won't work again until you open up the CSS and re-save it. Every other time I try to directly access my CSS, it works fine. But the other times, it doesn't work and I receive this server output:

[2010-08-01 12:49:37] ERROR NoMethodError: private method `gsub!' called for #<Class:0x7f6d0639ad80>
    /usr/lib/ruby/1.8/webrick/htmlutils.rb:16:in `escape'
    /usr/lib/ruby/1.8/webrick/httpresponse.rb:232:in `set_error'
    /var/www/rails-blog/vendor/rails/railties/lib/webrick_server.rb:94:in `handle_file'
    /var/www/rails-blog/vendor/rails/railties/lib/webrick_server.rb:73:in `service'
    /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
    /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    /usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
    /var/www/rails-blog/vendor/rails/railties/lib/webrick_server.rb:60:in `dispatch'
    /var/www/rails-blog/vendor/rails/railties/lib/commands/servers/webrick.rb:66
    /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
    /var/www/rails-blog/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in `require'
    /var/www/rails-blog/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
    /var/www/rails-blog/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in `require'
    /var/www/rails-blog/vendor/rails/railties/lib/commands/server.rb:49
    /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
    script/server:3
127.0.0.1 - - [01/Aug/2010:12:49:37 BST] "GET /stylesheets/scaffold.css HTTP/1.1" 500 343
- -> /stylesheets/scaffold.css?1280662371

The code I'm using to include the stylesheet is <%= stylesheet_link_tag 'scaffold' %>. I've restarted the Ruby server but with no effect. What could be causing this problem?

This is from reading one of the official guides.

This does not happen when running Mongrel.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

沧笙踏歌 2024-09-19 17:04:18

这是 WEBrick 中的一个错误,请参阅 http://www.ruby-forum.com/topic/ 206225

2010 年 6 月 10 日 03:19,Michael Pitman (mcp) 发布了

要继续使用 Webrick,而不是
切换到 Mongrel,你还可以
只需编辑第 15 行
lib/ruby/1.8/webrick/htmlutils.rb 到
阅读

<前><代码> str = 字符串? string.to_s.dup : ""

问题是NotModified
异常正在传递给
HTMLUtils::escape 作为一个类,而不是
比一个字符串(最初提出于
HTTPServlet::DefaultFileHandler)。
因为唯一能真正做到的事情
HTML 转义为字符串,应该
始终安全地转换输入
字符串。

我怀疑潜力
性能损失可能会阻止
像这样的解决方案从制作到
标准的 ruby​​ 库,但它是
简单的解决方法。

或者,在handle_file中
webrick的DispatchServlet的方法
(rails 中的 lib/webrick_server.rb
gem),在调用 res.set_error 之前
除了例外,你可以强制
err.message 是一个字符串,或者
甚至清除消息,因为我认为
无论如何它都会被丢弃
未修改。

迈克尔

This is a bug in WEBrick, see http://www.ruby-forum.com/topic/206225.

On 10.06.2010 03:19, Michael Pitman (mcp) posted:

To continue using Webrick, instead of
switching to Mongrel, you can also
just edit line 15 of
lib/ruby/1.8/webrick/htmlutils.rb to
read

  str = string ? string.to_s.dup : ""

The problem is that NotModified
exception is getting passed to
HTMLUtils::escape as a class, rather
than a string (originally raised in
HTTPServlet::DefaultFileHandler).
Since the only things that can really
be HTML escaped are strings, it should
be safe to always convert the input
to string.

I suspect that the potential
performance penalty may prevent a
solution like that from making it to
the standard ruby library, but it's a
simple workaround.

Alternatively, in the handle_file
method of webrick's DispatchServlet
(lib/webrick_server.rb in the rails
gem), before it calls res.set_error
with the exception, you could force
the err.message to be a string, or
even clear the message, since I think
it's discarded anyway for
NotModified.

Michael

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