繁体   English   中英

ruby on rails如何渲染没有布局和其他头部字段的页面

[英]ruby on rails how to render a page without layout and other head field

else
  respond_to do |format|
    format.html { render "tabelle/show" }
  end
end    

我想渲染页面...只有该页面中的代码....不要在rails上的ruby中添加<head> ... layout和<body>字段。 我只想在页面tabelle / show.html.haml中显示代码的结果

你可以这样做:

format.html { render "tabelle/show", :layout => false  } 

:layout => false

例:

render "tabelle/show", :layout => false

控制器:

layout false, only: [:method_name]

这在使用render_to_string时非常有用

如果您不想指定要使用的视图。

Rails非常聪明,可以根据您所在的Controller Action知道要使用哪个视图模板。

例如,如果您正在使用TabellesControllershow动作,则不需要在Controller Action中指定render "tabelle/show" ,因为Rails已经假设并且将自动尝试在app/views/tabelles/show.html.erb呈现文件app/views/tabelles/show.html.erb

因此,如果您坚持使用所有这些默认值,那么您可以使用以下内容进行渲染, 而无需使用典型的布局模板:

def show
  # Other stuff in your Controller Action.

  render layout: false
end

这将呈现app/views/tabelles/show.html.erb但不会自动显示布局模板。

在降噪。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM