ruby-on-rails - 在 Rails 3 : How do I render with layout in respond_with using a custom format?

标签 ruby-on-rails layout render

我的问题与这个问题中的问题相似,但相反。
How do I specify ":layout => false" in Rails' respond_with?

Controller 是一种文件转换器。它响应多种格式。一种格式应该呈现显示元数据的 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"会起作用,但显然不会。

如您所见,在将 Controller 粘贴到此处之前,我已经删除了 Controller 中的所有其他内容。格式“fil”作为 config/initializers/mime_types.rb 中的 text/html 格式添加到 mime 类型。我有我的 View 文件并渲染,但它周围没有任何布局。

我将不胜感激任何建议。我有一段时间无处可去,我在网上找到的任何东西都表明我的代码应该可以工作。

提前致谢。

最佳答案

发现如果我指定布局文件的确切路径和文件名,布局就会呈现。就我而言:

render :layout => '/layouts/application.html.haml'

关于ruby-on-rails - 在 Rails 3 : How do I render with layout in respond_with using a custom format?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3978800/

相关文章:

html - 变换 : translate(-50%, -50%)

javascript - 在渲染链接到 Navlink 的组件之前隐藏当前组件 - React Router

html - BFC/IFC参与方式的区别

render - Fabricjs:我的 Fabric.Object 子类的 _render 方法从未被调用

c++ - 当启用 msaa 时,gl_FragDepth 是否等于 gl_FragCoord.z?

ruby-on-rails - 将订阅模型与用户模型相关联

ruby-on-rails - 无法用 Cucumber "Can' 找出此错误,无法从中找到映射”

ruby-on-rails - 显示每个rspec示例的运行时

javascript - 如何将 ruby​​ 正则表达式翻译成 javascript? - (?i-mx :. .) 和 Rails 3.0.3

android - 如何在线性布局中右对齐