HTML ruby
Created By: chatGPT
HTML (HyperText Markup Language) is the standard markup language for creating web pages. It describes the structure of a webpage using elements represented by tags. Here’s a simple example of an HTML document:
<!DOCTYPE html>
<html>
<head>
<title>My First Web Page</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is a simple web page.</p>
</body>
</html>
Ruby is a dynamic, open-source programming language that focuses on simplicity and productivity. It has an elegant syntax that is easy to read and write. Below is an example of a simple Ruby script that prints 'Hello, World!':
puts 'Hello, World!'
To create a web application using HTML and Ruby, you might use a framework like Ruby on Rails. Rails is a full-stack web application framework that provides a structure for your application. Here’s how to create a simple Rails controller:
class WelcomeController < ApplicationController
def index
render 'index'
end
end
In your Rails view (located in
app/views/welcome/index.html.erb
), you can write HTML code mixed with Ruby. For example, displaying a message can look like this:<h1>Hello from Rails!</h1>
<p><%= @message %></p>
If you want to run a simple HTTP server to serve your HTML files using Ruby, you can use the built-in WEBrick server with the following code:
Combining HTML and Ruby makes it possible to create powerful and interactive web applications. You can use Ruby's flexibility to manipulate data and respond to user input in a clean and maintainable manner.require 'webrick'
server = WEBrick::HTTP::Server.new(:Port => 1234)
server.mount '/', WEBrick::HTTP::FileHandler, './public'
server.start