简体   繁体   English

Rails缓存扩展名错误的已保存文件

[英]Rails cache saved files with wrong extension

I have mime type defined 我定义了mime类型

Mime::Type.register "text/html", :demo

and controller which looks like this: 和控制器看起来像这样:

  caches_page :show
  def show
    .....
    render_location
  end

  def render_location
    ...
    respond_to do |format|
      format.html {
        expires_in 3.days, :public=>true
      }
      format.demo {
        headers['Content-type']  = 'text/html'
        render 'fields.html.erb', layout:nil
      }
      format.json do
        out = {
          :promo_text => 'text',
          :currencies => 'eee'
        }
        render json: out
      end
    end
  end

Route is set lite this: 路由设置为:

get '/prefix/*place', to: 'locations#show', as: 'location', defaults: {format:'html'}

For some reason file in cache folder is saved with .demo extension even when I request for "prefix/some-place" 出于某种原因,即使我请求“前缀/某处”,缓存文件夹中的文件也会以.demo扩展名保存。

I can't understand why this happens. 我不明白为什么会这样。

我发现,如果自定义扩展与另一个演示文稿共享Content-type,则必须使用register_alias对其进行定义。

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

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