Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 布局渲染不正确_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails 布局渲染不正确

Ruby on rails 布局渲染不正确,ruby-on-rails,ruby,Ruby On Rails,Ruby,我有一个页面,可以在推荐控制器的我的推荐操作中显示我的推荐 此操作的正确布局是layouts/frame,但我必须更改一些内容,因为现在它正在呈现layouts/application 以下是控制器中指定的布局: layout "layouts/frame", only: [:my_testimonials] layout "layouts/shares", only: [:new] 以下是控制台中的输出: Started GET "/my_testimonials/c4ca4238a0b92

我有一个页面,可以在推荐控制器的
我的推荐
操作中显示我的推荐

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

以下是控制器中指定的布局:

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)

正在显示证明,但布局不正确。正如我昨天所说,它正在工作,所以我必须更改一些小细节或某些东西的顺序。

Rails在“app/layouts/”文件夹中查找布局。看

因此,当您指定'layouts/frame'时,rails会查找'app/layouts/layouts/frame',但它显然找不到

将布局指令更改为以下内容:

layout "frame", only: [:my_testimonials]
layout "shares", only: [:new]
改变


我认为这应该行。

我倾向于认为
layout()
调用会覆盖以前的调用。在本例中,您为
:new
所做的最后一次
layout()
调用覆盖了为
:my_commentials
所做的调用

您还可以:

或指定每个操作的布局:

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

更新:


建议他们覆盖以前的电话。因此,将
版面称为“layouts/shares”,仅仅:[:new]
本质上是说对
:new
和“application”使用“shares”。

这可能没有什么区别,但我通常写
版面“frame”
,所以我认为
版面
文件夹是不需要的(你需要写的越少越好)@nathandva,抱歉,在发布我的答案之前,我没有看到你的评论。这没什么区别。我做了更改,但没有更改布局渲染。我现在假设它是某个地方的打字错误,但我看不到。我做了更改,但它仍然使用应用程序布局。我被难住了。还有什么我可以检查的吗?可能是检查您是否没有在视图中呈现应用程序布局,或者只是重新启动应用程序。我做了更改,但它仍在使用应用程序布局。我被难住了。还有什么我可以查的吗?@spuggy:如果没有其他相关问题,别忘了接受答案。
layout 'frame'
layout :set_layout

protected

def set_layout
  case action_name.to_sym
  when :my_testimonials
    'frame'
  when :new
    'shares'
  else
    'application'
  end
end
def my_testimonials
  respond_to do |format|
    format.html { render :layout => 'frame' }
  end
end