Ruby on Rails is by far my favorite framework to develop web applications. It is simple and complex enough to develop, pretty much all your needs. Whether you are a startup or a developer in the making, it’s a great tool to use to accomplish great things.
With the goal of building dynamic web applications, we will start by developing a static landing page.
Rules
For this guide, please make sure to type each terminal command exactly as you see it.
Install Ruby
$ ruby --version
// 2.6.4
If your ruby version is not 2.6.4, then you need to install RVM and download the right version of Ruby from your terminal.
Install Homebrew
Homebrew is a package manager that allows you to download and clone software from github. You will need it to download software that will allow you to create your Ruby on Rails environment.
$ brew --version
If you don’t see anything, then you need to download Homebrew, with the command below:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install RVM (Ruby version Manager)
Rvm is a ruby manager. It allows you to use install and use different versions of ruby. You can check if you have it by checking the version,
$ rvm --version
If you don’t get a version, then it means you don’t have it. So you need to install it by following the commands below:
$ \curl -sSL https://get.rvm.io | bash$ source ~/.bash_profile $ rvm install ruby 2.6.4$ rvm use 2.6.4
Install Yarn
Yarn is a tool that allows you to have easy access to any packages you download for your apps. It caches your packages and makes accessing packages much faster.
First, check if you have it by doing:
$ yarn --version
If you don’t see anything, then download it with the command below.
$ brew install yarn
Install Rails
Rails is a framework that allows you access to many features when building a web application. It gives you access to a server, database, etc. Install it below.
$ sudo gem install rails
Create your rails app:
$ cd Desktop$ rails new sample_app$ cd sample_app
Add your html and css files:
$ rails generate controller Home index
We will touch three files:
index.html.erb // this file should be in your app/views/home folder.
application.css . // this file should be in your app/assets/stylesheets folder.
routes.rb this file should be in app root directory.
In your routes.rb file (this file can be found in your /config folder, insert:
Rails.application.routes.draw do# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html root 'home#index'end
Start your rails server:
$ rails server
localhost:3000
You should have your website ready to go. It should be blank white and you can start by adding your html to your index.html.erb file.
You should see something like this below:
Challenge
Add an image and center the content of the page, like so:
For you to center the content, you have to change your application.css file.
body {
text-align: center;
}
Conclusion
Keep adding more stuff and be CREATIVE!