views:

96

answers:

2

My situation: View action of ReportsController should render pure html, but not as a file (to view it in browser and save it after). So for rendering I use view template view.html.erb and i neet to turn off any layouts for this action. But in other actions of this controller layouts should stay untouched. Works only turning off for whole controller like this:

ReportsController < ApplicationController
  layout false

But that doing it wrong :( for all the actions I tried to use something like this in action:

def view      
  @report = Report.new(params[:report])
  unless @report.valid?
    render :action => 'new' and return
  else
    render :layout => false     
  end   
end

What should I do besides to kill myself.

+2  A: 

Try this:

ReportsController < ApplicationController
  layout nil
  layout 'application', :except => :view
mckeed
It seems like this directive works wrong (or unexpected). I tried to use some combinations of these parameters (:only, :except). But it worked strange removing all the layouts for all the actions. I think it's because of nil or false instead of 'layoutname'. And system tries to use 'controllername' layouts for all the other actions ignoring application layout. Try to play with this parameters and you'll understand what this all about.
Antiarchitect
You're right, `:only` doesn't work properly on `layout nil`. I was able to get it working by nilling the layout and adding it back with the exception, however. I've updated my answer.
mckeed
A: 

You can define conditional layouts. Check this out here. Try to use layout ..., :except => ...

fifigyuri