4
我的问题与此问题中的问题类似,但相反。 How do I specify ":layout => false" in Rails' respond_with?在Rails 3中:如何使用自定义格式在respond_with中进行布局渲染?
该控制器是一种文件转换器。它响应很多格式。一种格式应该呈现显示元数据的html布局。与大多数其他格式不同,此格式需要呈现布局。问题是我无法说服Rails来渲染它。
class CustomFilesController < ApplicationController
respond_to :all, :only => :show
def show
@custom_file = CustomFile.find(params[:id])
respond_with(@custom_file) do |format|
format.html {}
format.xml {}
format.json {}
format.fil {
puts '>>>>> IN FIL <<<<<'
render :layout => true
}
format.any {
file = @custom_file.as(:type => params[:format], :size => params[:size]) ## the REAL path to the file
(file.nil? || @custom_file.nil?) ? head(:not_found) : send_file(file, :disposition => 'inline', :url_based_filename => true)
}
end
end
end
我以为“:layout => true”会工作,但显然不是。
正如你所看到的,我已经剥去了控制器中的所有其他东西,然后粘贴在这里。格式“fil”作为config/initializers/mime_types.rb中的文本/ html格式添加到MIME类型中。我有我的视图文件,它呈现,但没有任何布局。
我将不胜感激任何意见。现在我已经无处可去,我在网上找到的任何东西都表明我的代码应该可以工作。
在此先感谢。
您是否尝试指定布局的路径? ':layout =>'/ layouts/mylayout'' – Yannis 2010-10-20 16:12:02
我试过了“应用程序”和“不存在”。当我将它设置为不存在的布局时,我得到缺少的布局错误。当我将它设置为现有的时候,我会得到相同的空白结果。 – 2010-10-20 16:45:38