关闭布局以执行一项操作 [英] Turn off layout for one of action

查看:44
本文介绍了关闭布局以执行一项操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况: ReportsController的查看操作应呈现纯html,但不能呈现为文件(在浏览器中查看并在之后保存).因此,对于渲染,我使用视图模板view.html.erb,并且我需要关闭此操作的所有布局.但是在此控制器的其他操作中,布局应保持不变. 只能对整个控制器关闭,如下所示:

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

我该怎么办?

推荐答案

尝试一下:

ReportsController < ApplicationController
  layout false
  layout 'application', :except => :view

这篇关于关闭布局以执行一项操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆