[英]Ruby on Rails - How do I render an action without the application layout?
[英]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知道要使用哪個視圖模板。
例如,如果您正在使用TabellesController
的show
動作,則不需要在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.