Rails:如何在 application.html.erb 布局中添加元素而不是键入硬编码的 html 元素?
如何在 application.html.erb 布局中添加元素而不是键入硬编码的 html 元素?
是否可以像在 cakephp 中那样做到这一点? http://book.cakephp.org/view/1081/Elements
How can i add elements in application.html.erb layout instead of typing hard coded html element ?
Is it possible to do this like we can do this in cakephp?
http://book.cakephp.org/view/1081/Elements
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来像 Rails Partials 或助手
Sounds like Rails Partials or helpers
您可以使用帮助程序来处理小片段,甚至可以使用部分帮助程序来处理较大的 html 块。 cakepho 元素看起来更类似于partials。在 Rails 中,您将有一个部分用于渲染组件,例如 _nav.html.erb 中的导航,并且可能需要一些局部变量来渲染。在您的 application.html.erb 中,您将渲染部分:
这将是您阅读的一个很好的资源: http ://guides.rubyonrails.org/layouts_and_rendering.html
You could use helpers for small snippets or even partials for larger html chunks. The cakepho element looks more similar to partials. In rails you would have a partial for rendering a component like a nav in _nav.html.erb and it may require a few local variables to render. In your application.html.erb you would render the partial:
This would be a great resource for you to read: http://guides.rubyonrails.org/layouts_and_rendering.html
助手是您编写的用于帮助创建视图的 Ruby 方法。这是一个有用的:
在您的视图中,您可以调用
sentence_links Player.limit(3)
来输出:Helpers are ruby methods you write to help create views. Here's a useful one:
And the in your views you can call
sentence_links Player.limit(3)
to output: