我在做Lynda.com的rails教程,他们解释了如何呈现另一个视图,而不是使用render('methodname')的默认视图。Rails控制器:可以嵌套渲染视图吗?
但是,我注意到这个渲染不是“嵌套”的。例如,在下面的代码中,localhost:3000/demo/index会在views/demo/hello.html.erb中生成视图,而localhost:3000/demo/hello会呈现文本'Hello there'。
有没有一种方法可以进行“嵌套”渲染,即在此示例中请求演示/索引将返回'Hello there'?
(此外,一些使用案例嵌套渲染就好了。我问只是出于好奇。)
class DemoController < ApplicationController
def index
render ('hello')
end
def hello
render(:text => 'Hello there')
end
end