![Glock 19 Frame DD19.2](/_next/image?url=https%3A%2F%2F3dgunbuilder.com%2Fwp-content%2Fuploads%2F2022%2F11%2Fdd19-3d-g19-frame.webp&w=1920&q=75)
Glock 19 Frame DD19.2
The FMDA dd19.2 3D Printed Glock Pistol Frame
Welcome to the first tutorial in our series on building a landing page with Ruby on Rails. In this tutorial, we'll learn how to create a basic landing page using Ruby on Rails.
Prerequisites
Before we get started, you'll need to have the following:
- Ruby 2.6.3 or higher installed on your computer
- The Rails gem installed on your computer (you can install it using
gem install rails
) - A text editor (we recommend using VS Code)
Step 1: Create a new Rails app
To get started, we'll create a new Rails app. Open up your terminal and run the following command:
rails new landing-page
This will create a new Rails app called landing-page
in the current directory. Next, we'll navigate into the landing-page
directory and start the Rails server:
cd landing-page
rails server
This will start the Rails server on port 3000. You can now visit http://localhost:3000
in your browser to view your new Rails app.
Step 2: Create a new controller
Now that we have our Rails app set up, we can start creating our landing page. To do this, we'll create a new controller called PagesController
. Run the following command to create the controller:
rails generate controller Pages
This will create a new controller called PagesController
in the app/controllers
directory. Next, we'll add a new action called home
to the PagesController
:
class PagesController < ApplicationController
def home
end
end
This will create a new action called home
in the PagesController
. Next, we'll add a new route to the config/routes.rb
file:
Rails.application.routes.draw do
root 'pages#home'
end
This will set the root
route to the home
action in the PagesController
. Now, if you visit http://localhost:3000
in your browser, you should see the following message:
Yay! You’re on Rails!
Step 3: Create a new view
Now that we have our controller set up, we can start creating our landing page. To do this, we'll create a new view called home.html.erb
in the app/views/pages
directory. Open up the home.html.erb
file and add the following HTML:
<!DOCTYPE html>
<html>
<head>
<title>Landing Page</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
This will create a basic HTML page with a heading that says "Hello, World!". Now, if you visit http://localhost:3000
in your browser, you should see the following message:
Hello, World!
Step 4: Add some CSS
Now that we have our landing page set up, we can start adding some CSS. To do this, we'll create a new file called application.css
in the app/assets/stylesheets
directory. Open up the application.css
file and add the following CSS:
body {
background-color: #f5f5f5;
}
This will set the background color of the body to #f5f5f5
. Now, if you visit http://localhost:3000
in your browser, you should see the following message:
Hello, World!
Step 5: Add some JavaScript
Now that we have our landing page set up, we can start adding some JavaScript. To do this, we'll create a new file called application.js
in the app/assets/javascripts
directory. Open up the application.js
file and add the following JavaScript:
console.log("Hello, World!");
This will log the message "Hello, World!" to the console. Now, if you visit http://localhost:3000
in your browser, you should see the following message:
Hello, World!
Conclusion
In this tutorial, we learned how to create a basic landing page using Ruby on Rails. In the next tutorial, we'll learn how to add a navigation bar to our landing page.
Check out this Twitter thread for more information on this topic:
%[https://twitter.com/rubyonrails/status/479095701939306496]
ChatGPT
This post was generated by ChatGPT and is an example of how you can create your own blog posts with Scalerepo.
Scalerepo is a production-ready SaaS boilerplate
Skip the tedious parts of building auth, org management, payments, and emails
See the demo