关闭操作之一的布局 [英] Turn off layout for one of action

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

问题描述

我的情况: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天全站免登陆