ruby on rails 的public下的文件是如何显示的?

我想建立一个新文件夹,里面直接显示html文档?不知可以不可以?
如在public下建立caring,里面是一些独立的html文档,能否在IE中直接显示?

我知道所有url均是要经过路由的
但我看网站中不少地址,如css,公用图片,也没指定控制器和视图,一样能显示,只是在后加面了一些数字?

路由中也没定义,他们是如何显示的?

放books.html在public/caring目录下,访问http://localhost:3000/caring/books.html即可。

静态文件可以直接显示。

Rails的配置中有个
onfig.action_controller.perform_caching = true
表示允许静态页面缓存

我感觉你看到,网站中有直接能够访问public下的静态html页面和图片,就是因为他们的网站设置了静态页面缓存。

页面缓存的位置,规则如下:

[code="html"]
http://localhost:3000/blog/list => /public/blog/list.html
http://localhost:3000/blog/edit/5 => /public/edit/5.html
http://localhost:3000/blog => /public/blog.html
http://localhost:3000/ => /public/index.html
http://localhost:3000/blog/list?page=2 => /public/blog/list.html
[/code]

也就是说,大部分的public下的文件夹不是直接建立的,是action对应生成的。

如果,你一定要自定义,也可以这样改:
[code="irb"]
首先需要在你的 /config/environment.rb 中添加下面的代码

config.action_controller.page_cache_directory = RAILS_ROOT + "/public/cache/"
[/code]

而且,通常情况下,我们看到的网站,都不是mongrel直接支持的,都是Apache或者lighttpd配合的。所以,如果你想要能够直接访问也要做相应的配置:
[code="linux"]
httpd.conf的配置


...
# Configure mongrel_cluster

BalancerMember http://127.0.0.1:8030

RewriteEngine On
# Rewrite index to check for static
RewriteRule ^/$ /index.html [QSA]

# Rewrite to check for Rails cached page
RewriteRule ^([^.]+)$ $1.html [QSA]

# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://blog_cluster%{REQUEST_URI} [P,QSA,L]
...
lighttpd 的配置写法

server.modules = ( "mod_rewrite", ... )
url.rewrite += ( "^/$" => "/index.html" )
url.rewrite += ( "^([^.]+)$" => "$1.html" )
[/code]