【发布时间】:2024-01-15 05:23:01
【问题描述】:
我正在学习 Lynda.com rails 教程,他们解释了如何使用 render('methodname') 渲染另一个视图而不是默认视图。
但是,我注意到此渲染不是“嵌套”的。例如,在下面的代码中,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
【问题讨论】:
标签: ruby-on-rails controller rendering render