简体   繁体   中英

Rails caches_page :index in Wrong Location

I have a controller Projects in my Rails app with:

caches_page :index

However, instead of the cached file being generated at /public/projects/index.html it is located at /public/projects.html .

The web server (currently Mongrel) looks for */ directories before *.html files. So the http://…/projects request is routed through Rails and my index cache file is never served.

How can I tell caches_page :index to generate the file at /public/projects/index.html instead?

You can specify the directory by adding the following to your environment.rb config block

config.cache_store = :file_store, "#{RAILS_ROOT}/public/projects" 

A couple other things:

  1. The cache settings have changed some with the different version of Rails, it would be helpful to know what version you are running

  2. In general you're probably better off using the cache memory store instead of file store (if you have sufficient RAM in your box).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM