gpt4 book ai didi

ruby-on-rails - 布局渲染不正确

转载 作者:太空宇宙 更新时间:2023-11-03 16:03:43 25 4
gpt4 key购买 nike

我有一个页面,在推荐 Controller 的 my_testimonials 操作中显示我的推荐。

此操作的正确布局是 layouts/frame 但我必须更改某些内容,因为现在它正在呈现 layouts/application

这是在 Controller 中指定的布局:

layout "layouts/frame", only: [:my_testimonials]
layout "layouts/shares", only: [:new]

这是控制台的输出:

Started GET "/my_testimonials/c4ca4238a0b923820dcc509a6f75849b" for 105.228.65.202 at 2013-09-27 07:40:49 +0000
2013-09-27T07:40:49.470211+00:00 app[web.2]: Processing by TestimonialsController#my_testimonials as HTML
2013-09-27T07:40:49.686047+00:00 app[web.2]: Rendered testimonials/_testimonial.html.erb (2.6ms)
2013-09-27T07:40:49.686200+00:00 app[web.2]: Rendered testimonials/my_testimonials.html.erb within layouts/application (79.2ms)

正在显示推荐,但布局不正确。正如我昨天所说的那样,它在工作,所以我一定是更改了一些小细节或某些东西的顺序。

最佳答案

我倾向于认为 layout() 调用会覆盖之前的调用。在这种情况下,您为 :new 调用的最后一个 layout() 覆盖了为 :my_testimonials 调用的调用。

您也可以choose the layout at runtime :

layout :set_layout

protected

def set_layout
case action_name.to_sym
when :my_testimonials
'frame'
when :new
'shares'
else
'application'
end
end

或者为每个 Action 指定你的布局:

def my_testimonials
respond_to do |format|
format.html { render :layout => 'frame' }
end
end

更新:

The code建议他们确实会覆盖以前的电话。所以调用 layout "layouts/shares", only: [:new] 本质上是说对 :new 使用“shares”,否则使用“application”。

关于ruby-on-rails - 布局渲染不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19045563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com