Quick guides for starting a new Ruby on Rails app from scratch
Create new app, set up development pipeline, push updates, and install Bootstrap
Note: The following guides assume your development environment is already set up, including Ruby, Rails, database, version control, and deployment. For these examples, I will use PostgreSQL, GitHub, and Heroku.
Create new Ruby on Rails app
- Create application and set database type (where
appname
is your app’s name andpostgresql
is the database type)
rails new appname --database=postgresql
2. Adjust config/database.yml
and connect database
- Add the following under
default
(wherepostgres
is database username andpassword
is database password):
username: postgres
password: password
host: localhost
- Also, comment out login under
production
# username: appname
# password: <%= ENV['APPNAME_DATABASE_PASSWORD'] %>
3. Navigate to the new app folder (cd appname
) and create database
rake db:create
4. Start Rails server
rails s
5. In your browser, navigate to http://localhost:3000/
. You should see a page similar to the image below.
Set up development pipeline
- Initialize empty git repository
git init
2. Stage everything in current folder
git add --all
3. Make the first commit of application code
git commit -am “Initial commit”
4. Set up GitHub
- Log in to GitHub
- Create a new repository
- Run commands provided to “push an existing repository from the command line” using SSH
5. Set up Heroku
- Create Heroku app
heroku create [appname]
- Push to Heroku
git push heroku master
Update to GitHub
- Stage all updated files
git add --all
2. Commit staged files and add a comment describing the changes
git commit -am "[comment]"
3. Push commit(s) to GitHub
git push origin master
Update to Heroku
(When GitHub is up-to-date)
git push heroku master
Install Bootstrap
- Check that
jquery-rails
gem is installed. If not, install it.
- Add
gem 'jquery-rails'
toGemfile
and runbundle install
- Open
assets/javascripts/application.js
and add the following aboveturbolinks
:
//= require jquery
//= require jquery_ujs
2. Add popper_js
and bootstrap
to your Gemfile
gem 'popper_js', '~> 1.14.5'
gem 'bootstrap', '>= 4.3.1'
source 'https://rails-assets.org' do
gem 'rails-assets-tether', '>= 1.3.3'
end
(Note: The versions shown are the most recent at the time of writing. Check for updated versions and adjust your Gemfile
accordingly)
3. Run bundle install
and restart your server to make the files available through the pipeline
4. Rename application.css
to application.scss
mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss
5. Make a new file at app/assets/stylesheets/master.scss
and add the following code into it:
@import “bootstrap”;
6. Adjust app/assets/javascripts/application.js
to include the following between turbolinks
and require_tree
:
//= require popper
//= require tether
//= require bootstrap-sprockets
Any suggestions for improving these guides are welcome! I’m trying to keep the steps concise while still including enough information.