Why is the view of Rails application in the format *.erb.html
? What does "erb" mean?
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
相关文章
- Ruby using wrong version of openssl
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
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
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.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.
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
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.
Embedded Ruby, also called ERb, is the primary template system for including dynamic content in web pages. --Michael Hertl