Mongrel:如何处理 .rhtml 文件中的 erb
我正在尝试为某些 Web 开发提供静态内容,并使用几行 erb 来模拟真实服务器将执行的操作。我已经在这里使用 WEBrick 执行此操作: http://ceronio.net/2011/06/nice-web-server-script-to-server-any-directory-using-webrick,但现在我想用 Mongrel 来做到这一点。
到目前为止我的代码是这样的:
#!/usr/bin/ruby
require 'rubygems'
require 'mongrel'
Mongrel::DirHandler.add_mime_type('.rhtml', 'text/html')
server = Mongrel::HttpServer.new("localhost", 2000)
server.register("/", Mongrel::DirHandler.new(Dir::pwd))
server_thread = server.run
server_thread.join
但是当我访问我的index.rhtml文件时,它不会处理<% %>中的内容。标签,但只是将文件按原样传递给浏览器。
使用 WEBrick,不需要任何额外的操作。我需要做什么才能在 .rhtml 文件中处理服务器端 Ruby 代码?
I am trying to serve up static content for some web development, with a few lines of erb to simulate what the real server will do. I already did this with WEBrick here: http://ceronio.net/2011/06/nice-web-server-script-to-server-any-directory-using-webrick, but now I want to do this with Mongrel.
My code so far is like this:
#!/usr/bin/ruby
require 'rubygems'
require 'mongrel'
Mongrel::DirHandler.add_mime_type('.rhtml', 'text/html')
server = Mongrel::HttpServer.new("localhost", 2000)
server.register("/", Mongrel::DirHandler.new(Dir::pwd))
server_thread = server.run
server_thread.join
But when I access my index.rhtml file, it does not process the content in the <% %> tags, but just passes the file as is to the browser.
With WEBrick, nothing additional was required. What do I need to do here to get the server-side Ruby code processed in the .rhtml file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在查看了 Mongrel 中 DirHandler 类的代码后,似乎该类并不是为了对文件进行任何处理而创建的,而只是按原样提供它。
看来在 Mongrel 中做到这一点的唯一方法是修改 DirHandler 或编写自己的 HttpHandler。
After looking through the code of the DirHandler class in Mongrel, it seems that this class is not made for applying any processing to a file, but just serving it up as is.
It seems the only way to do this in Mongrel would be to modify DirHandler or write your own HttpHandler.