渲染:动作和渲染:模板之间的区别
render :action => 和有什么区别? “new” 和 render :template => “用户/新”
?我听说渲染模板可以用于其他控制器的视图。是这样还是两者之间的渲染布局有什么区别吗?对于 render :template,是否需要定义一个操作,或者视图页面本身就足够了?
What is the difference between render :action => "new"
and render :template => "users/new"
? I have heard that rendering template, we can use for views from other controllers. Is that it or is there any difference in rendering layout also between the two? For render :template, is it neccessary to have an action defined or is the view page itself enough?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有区别。
render :template => 'some/thing'
与render 'some/thing'
相同,也与render :action =>; 相同。 'thing'
如果我们在some
控制器中。来自 Ruby On Rails 指南;
There is no difference.
render :template => 'some/thing'
is the same as justrender 'some/thing'
, as well as the same asrender :action => 'thing'
if we are in thesome
controller.From Ruby On Rails guide;
以前,在控制器操作中调用渲染
“foo/bar”
相当于渲染文件:“foo/bar”
。在 Rails 4.2 中,这已更改为render template: "foo/bar"
。如果您需要渲染文件,请更改代码以使用显式形式(渲染文件:“foo/bar”
)。http://guides.rubyonrails.org/4_2_release_notes.html#render -带有字符串参数
Previously, calling render
"foo/bar"
in a controller action was equivalent torender file: "foo/bar"
. In Rails 4.2, this has been changed to meanrender template: "foo/bar"
instead. If you need to render a file, please change your code to use the explicit form (render file: "foo/bar"
) instead.http://guides.rubyonrails.org/4_2_release_notes.html#render-with-a-string-argument
将渲染该控制器操作的视图并应用
some_layout_in_layout_folder
布局的资源设置(javascript
、CSS
)。如果您在控制器操作中编写此内容,它将使用指定布局的样式以及类开头定义的任何布局(如果有)
will render the view of that controller action and apply the asset settings (
javascript
,CSS
) of thesome_layout_in_layout_folder
layout.If you write this in a controller action, it will use the styling of the specified layout in conjunction with any layout defined at the beginning of the class, if any