[英]create new page (not having the layout specified in /app/layouts/* files) in rails
Most of my view files have the same layouts, hence it was reasonable to define layouts/application.html.haml
(and other header
, footer
files). 我的大多数视图文件都具有相同的布局,因此定义layouts/application.html.haml
(以及其他header
, footer
文件)是合理的。
But now I need to create a page that does NOT have any of those styling. 但是现在我需要创建一个没有任何样式的页面。 In fact, I just want a plain page with a header. 实际上,我只想要一个带标题的普通页面。
How do I do that? 我怎么做?
You can specify the layout in the controller like so: 您可以在控制器中指定布局,如下所示:
class ThingsController < ApplicationController
layout "some_layout"
# rest of the controller
end
This would look for app/views/layouts/some_layout.html.erb
这将寻找app/views/layouts/some_layout.html.erb
You can also use a method to choose the layout: 您还可以使用方法来选择布局:
class ThingsController < ApplicationController
layout :choose_layout
def choose_layout
current_user.cat? ? "cat" : "dog"
end
# rest of the controller
end
I think you're after. 我想你是在追求。 In your controller, assuming your action is called myaction 在您的控制器中,假设您的操作称为myaction
def myaction
# do here whatever you need to do and then
render :layout => false
end
See options for render in Rails Guide: layouts and redendering 请参阅Rails指南中的渲染选项:布局和重新缩放
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.