erb 是什么意思?
为什么 Rails 应用程序的视图采用 *.erb.html
格式? “erb”是什么意思?
Why is the view of Rails application in the format *.erb.html
? What does "erb" mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
erb 代表“嵌入式 Ruby”。
.html.erb
或.erb.html
文件是嵌入了 Ruby 代码的 HTML; Rails 将评估 Ruby 以动态地将内容添加到文件中,并输出一个“纯”HTML 文件进行渲染。erb stands for "Embedded RuBy". A
.html.erb
or.erb.html
file is HTML with Ruby code embedded in; Rails will evaluate the Ruby to add content to the file dynamically, and will output a "pure" HTML file for rendering.正如 @Chowlett 之前提到的,erb 代表嵌入式 Ruby。当您将任何文件定义为“.html.erb”时,这意味着它是一个嵌入了 ruby 代码的 HTML 文件,它类似于 Rails 文件的“.rhtml”扩展名。
您可以看到“.html.erb”和“.rhtml”之间的详细且良好的区别 点击这里
与“.rhtml”相同,也可以将“.rjs”扩展名重命名为“.js.erb”或“.rxml”重命名为“.xml.erb”
这种格式将内容类型与模板引擎分开,在本例中为“erb”。
As @Chowlett mentioned before, erb stands for Embedded Ruby. When you define any file as ".html.erb" that means it's an HTML file with ruby code embedded in it and it is similar to ".rhtml" extension of rails file.
You can see a detailed and nice difference between ".html.erb" and ".rhtml" Click Here
Same as ".rhtml", you can also rename ".rjs" extension to ".js.erb" or ".rxml" to ".xml.erb"
This format separates out content type from template engine which is "erb" in this case.
来自 Stuart Ellis 的ERB 模板简介:
原始文章包含更多详细信息和使用 ERB 的简短指南。您还可以阅读官方文档。
注意:上面引用的块之前是其他用户作为答案发布的,没有链接到ERB 模板简介或承认这不是该用户的工作。该帖子因抄袭而被(正确地)删除。不过,我认为这是一个有用的答案,因此我重新发布了该引用,并正确注明了原作者 Stuart Ellis 的归属。
From Stuart Ellis's An Introduction to ERB Templating:
The original article contains more detail and a short guide to using ERB. You can also read the official docs.
Note: the quoted block above was previously posted as an answer by another user without linking to An Introduction to ERB Templating or acknowledging that it was not that user's work. That post was (rightly) deleted for plagiarism. However, I thought it was a useful answer, so I've reposted the quote giving proper attribution to Stuart Ellis, the original author.
嵌入式 Ruby,也称为 ERb,是在网页中包含动态内容的主要模板系统。 ——迈克尔·赫特尔
Embedded Ruby, also called ERb, is the primary template system for including dynamic content in web pages. --Michael Hertl
来自 模板格式
包含 ERB 模板的文件可以具有任意名称,但按照惯例,文件名应以 .erb 扩展名结尾。 Rails 要求模板文件具有输出类型的扩展名,后跟 .erb,因此像layout.html.erb 这样的名称表示 HTML 模板。
erb 文件只会输出文本。而已。什么文本取决于文件内静态文本和 ruby 代码的混合。您可以使用 erb 生成 html,这是 Rails 中的默认用法,因为这就是浏览器显示页面所需的内容。
在 ruby 中,有一些默认设置,其中一个默认设置是控制器将呈现 html 页面。但是,如果您为其编写一个 Web api,则可以轻松地使其使用 .xml 或 .json 或 .csv 进行响应。
Erb 是一个生成文本的库类。而已。它需要一个包含静态文本和混合 ruby 代码的文件。它将运行 ruby 代码并将结果写入另一个文件,如果您的控制器是 html
from template-format
A file that contains an ERB template may have any name, but it is the convention that the name of file should end with the .erb extension. Rails requires template files to have the extension of the output type, followed by .erb, so that a name like layout.html.erb indicates a HTML template.
erb files will simply output text. Nothing more. What text is depending on the mix of static text and ruby code inside the file. You can use erb to generate html which default usage in Rails, because that's what browsers need to display a page.
In ruby there are certain defaults One default is that a controller will render a html page. But you can easily make it respond with .xml or .json or .csv if you write a web api for it
Erb is a library class that generates text. Nothing more. It expects a file that contains static text and ruby code mixed. It will run the ruby code and write the result to another file which in case for your controllers is html
ERB 是 Ruby 中的模板类,通常用在 Rails 中的 .rhtml 或 .erb.html(嵌入 Ruby 的 HTML)中。
这是 Ruby 文档的详细信息。
http://ruby-doc.org/stdlib-1.9 .3/libdoc/erb/rdoc/ERB.html
ERB is templating Class in Ruby and is often used in .rhtml or .erb.html (HTML with embedded Ruby) in rails.
Here is a nice detail on the Ruby docs.
http://ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html