4

My problem is similar to the one in this question, but the opposite. How do I specify ":layout => false" in Rails' respond_with?

The controller is sort of a file converter. It responds to many formats. One format is supposed to render an html layout showing metadata. This format need the layout to be rendered, unlike most other formats. Problem is I can't 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 ":layout => true" would work but apparently not.

As you can see I have stripped away everything else in the controller before pasting it in here. The format "fil" is added to the mime types as a text/html format in config/initializers/mime_types.rb. I have my view file in place and it renders, but without any layout around it.

I would appreciate any advice. I have gotten nowhere for a while now and anything I find online suggests my code should work.

Thanks in advance.

Community
  • 1
  • 1
Martin Westin
  • 1,419
  • 1
  • 14
  • 25
  • Did you try to specify the path to your layout? `:layout => '/layouts/mylayout'` – Yannis Oct 20 '10 at 16:12
  • I've tried "application" and "nonexistent". When I set it to a nonexistent layout I get a missing layout error. When I set it to an existing one I get the same blank result. – Martin Westin Oct 20 '10 at 16:45

1 Answers1

2

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

render :layout => '/layouts/application.html.haml'
Martin Westin
  • 1,419
  • 1
  • 14
  • 25