mew*_*sic 25 ruby ruby-on-rails render
else
respond_to do |format|
format.html { render "tabelle/show" }
end
end
Run Code Online (Sandbox Code Playgroud)
我想渲染页面...只有该页面中的代码....不在轨道上的ruby中添加<head>...布局和<body>字段.我只想在页面tabelle/show.html.haml中显示代码的结果
fme*_*dez 34
你可以这样做:
format.html { render "tabelle/show", :layout => false }
Run Code Online (Sandbox Code Playgroud)
加
:layout => false
Run Code Online (Sandbox Code Playgroud)
例:
render "tabelle/show", :layout => false
Run Code Online (Sandbox Code Playgroud)
小智 7
控制器:
layout false, only: [:method_name]
Run Code Online (Sandbox Code Playgroud)
这在使用render_to_string时非常有用
Rails 足够聪明,可以根据您所在的控制器操作知道要使用哪个视图模板。
例如,如果您使用的是 的show操作,则TabellesController不需要render "tabelle/show"在控制器操作中指定,因为 Rails 已经假定并会自动尝试在app/views/tabelles/show.html.erb.
因此,如果您坚持使用所有这些默认值,那么您只需使用以下内容即可在没有典型布局模板的情况下进行渲染:
def show
# Other stuff in your Controller Action.
render layout: false
end
Run Code Online (Sandbox Code Playgroud)
这将app/views/tabelles/show.html.erb自动呈现但没有布局模板。
诺斯。