In Rails 3: How to render with layout in response_with using custom format?

My problem is similar to the problem in this question, but vice versa. How to specify ": ​​layout => false" in Rails' response_with?

A controller is a kind of file converter. It responds to many formats. One format is to display an html layout displaying metadata. This format requires a layout to be displayed, unlike most other formats. The problem is that I cannot convince Rails to render it.

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 

I thought that ": layout => true" would work, but apparently not.

As you can see, I removed everything else in the controller before inserting it here. The "fil" format is added to the mime types as text / html format in config / initializers / mime_types.rb. I have a file for viewing in place, and it displays, but without a layout.

I would be grateful for any advice. I am not going anywhere, and everything that I find on the Internet suggests that my code should work.

Thanks in advance.

+4
source share
1 answer

Found that the layout displays if I specify the exact path and file name of the layout. In my case:

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

All Articles