class UserController < ApplicationController
def test
render :partial => 'test'
end
end
上面的代码不包括 _test.erb 部分中的默认应用程序布局
但是如果我使用
class UserController < ApplicationController
def test
end
end
部分 test.erb 加载了默认的应用程序.html布局
另外,如果我使用
render :partial => 'test', :layout => 'application'
我收到一个错误,因为 rails 搜索了_application.html而默认布局是应用程序.html
使用以下代码片段,我在控制器中包含布局"应用程序"也不会加载应用程序.html布局。
class UserController < ApplicationController
layout 'application'
def test
render :partial => 'test'
end
end
我做错了什么,还是 Rails 在渲染部分时没有将应用程序布局作为默认布局。
最好从视图中呈现部分。
<%= render "path/to/partial", :variable => @variable %>