What is MIME type "text/html+ruby"?
A MIME type is a string that tells browsers and other tools how to handle a particular kind of file.
text/html+ruby is a MIME type for files that mix HTML with Ruby code. It lets servers process embedded Ruby instructions inside an HTML document.
The primary use is to build dynamic web pages. The server parses the Ruby code. The code runs and produces HTML. Then, the browser receives a pure HTML page.
- Dynamic Content Generation – It enables server-side scripting.
- Templating – It integrates Ruby code directly into HTML.
- Process Flexibility – Developers can mix logic with markup for custom output.
Files using this MIME type commonly carry the formats RHTML and RHTM. Both are known as eRuby HTML documents.
For further details, see ERuby on Wikipedia and MIME types documentation on MDN.
Associated file extensions
Usage Examples
HTTP Header
When serving content with this MIME type, set the Content-Type header:
Content-Type: text/html+ruby
HTML
In HTML, you can specify the MIME type in various elements:
<a href="file.dat" type="text/html+ruby">Download file</a>
Server-side (Node.js)
Setting the Content-Type header in Node.js:
const http = require('http');
http.createServer((req, res) => {
res.setHeader('Content-Type', 'text/html+ruby');
res.end('Content here');
}).listen(3000);
Associated file extensions
FAQs
What is the text/html+ruby MIME type used for?
This MIME type is used for Embedded Ruby (eRuby) documents, which allow Ruby scripts to be embedded directly within HTML code. It is most commonly associated with legacy web applications using the rhtml extension to generate dynamic content on the server side.
Can web browsers render text/html+ruby files directly?
No, standard web browsers like Chrome or Firefox cannot execute Ruby code. The web server must process the text/html+ruby file first, executing the embedded scripts to generate standard text/html, which is then sent to the browser for display.
How do I fix my server sending .rhtml files as downloads?
If your browser downloads the file instead of displaying a page, your server is likely missing the configuration to execute Ruby code. You need to configure your web server (such as Apache or Nginx) to pass these files to a Ruby handler (like Passenger or CGI) instead of serving them as static files.
Is text/html+ruby the same as .erb files in Rails?
They serve the same purpose, but text/html+ruby and the .rhtml extension are considered legacy formats compared to modern .html.erb templates. While older servers explicitly used this MIME type, modern frameworks like Ruby on Rails typically handle template processing internally without relying on this specific Content-Type header.
What are the security risks of using text/html+ruby?
The primary risk is source code exposure if the server configuration fails. If the server sends the file as text/plain or fails to execute the Ruby block, users might view the raw source code, which could contain sensitive logic or database credentials.
How do I edit a file with the text/html+ruby MIME type?
Since these files are text-based, you can edit them with any code editor like VS Code, Sublime Text, or Notepad. However, to preview the changes, you must run the file through a Ruby environment or a local web server configured to parse eRuby.
General FAQ
What is a MIME type?
A MIME (Multipurpose Internet Mail Extensions) type is a standard that indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.
MIME types are important because they help browsers and servers understand how to process a file. When a browser receives a file from a server, it uses the MIME type to determine how to display or handle the content, whether it's an image to display, a PDF to open in a viewer, or a video to play.
MIME types consist of a type and a subtype, separated by a slash (e.g., text/html, image/jpeg, application/pdf). Some MIME types also include optional parameters.
How do I find the MIME type for a file?
You can check the file extension or use a file identification tool such as file --mime-type on the command line. Many programming languages also provide libraries to detect MIME types.
Why are multiple MIME types listed for one extension?
Different applications and historical conventions may use alternative MIME identifiers for the same kind of file. Showing them all helps ensure compatibility across systems.