[RUBY] Rails Tutorial record and memorandum # 1 "From installation to hello_app deployment + error handling"

It is a learning record. If you proceed as it is, there will be some parts that will get stuck, so I will write about the correspondence.

Ruby installation

https://railsgirls.jp/install

Rails installation

gem install rails --no-document
rails -v

When specifying the version

gem install rails -v 5.1.6

Project creation

Created by specifying the version with a command.

rails _5.1.6_ new hello_app
cd hello_app

Gemfile Package management file. The package seems to be downloaded locally. If you write a package that is not locally and bundle install, you will get an error. It seems that bundle update downloads packages that are not local.

Gemfile


source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '5.1.6'
# Use Puma as the app server
gem 'puma', '3.9'
# Use SCSS for stylesheets
gem 'sass-rails', '5.0.6'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '3.2.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '4.2.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '5.0.1'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '2.6.4'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem 'jquery-rails', '4.3.1'

group :development, :test do
  gem 'sqlite3',      '1.3.13'
  gem 'byebug', '9.0.6', platform: :mri
end

group :development do
  gem 'web-console',           '3.5.1'
  gem 'listen',                '3.1.5'
  gem 'spring',                '2.0.2'
  gem 'spring-watcher-listen', '2.0.1'
end

group :production do
  gem 'pg'#, '0.20.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
bundle update
bundle install --without production

Since an error occurs when installing sqlite, refer to the following article. https://qiita.com/shuhey/items/8cd28aed5906fb5fa6ec

Start-up

rails server

Ruby on Rails is MVC

The usual.

Browser
 |
Controller - Model
 |            |
View         Database

hello function creation

app/controllers/application_controller.rb


  def hello
    render html: "hello world!"
  end

config/routes.rb


Rails.application.routes.draw do
  root 'application#hello'
end

Changed database.yml for Heroku deployment

See the following article. https://qiita.com/kazukimatsumoto/items/a0daa7281a3948701c39

In the initial state, sqlite is used, but Heroku does not support sqlie. Heroku uses postgres, so rewrite production to postgres.

config/database.yml


production:
  <<: *default
  adapter: postgresql
  encoding: unicode
  pool: 5

Deploy to Heroku

heroku create
git add .
git commit -m "Initialize"
git push heroku master

Recommended Posts

Rails Tutorial record and memorandum # 1 "From installation to hello_app deployment + error handling"
Rails Tutorial Chapter 1 From Zero to Deployment [Try]
Rails Tutorial 4th Edition: Chapter 1 From Zero to Deployment
Rails Tutorial Records and Memorandum # 0
Chewing Rails Tutorial [Chapter 1 From Zero to Deployment] Second Half
Chewing Rails Tutorial [Chapter 1 From Zero to Deployment] First Half
[rails s error] md5.bundle and mysql installation error
Rails tutorial memorandum 1
Rails tutorial memorandum 2
[Rails] How to get success and error messages
Rails Tutorial Memorandum (Chapter 3, 3.1)
Rails Tutorial Memorandum (Chapter 3, 3.3.2)
From 0 to Ruby on Rails environment construction [macOS] (From Homebrew installation to Rails installation)
From Ruby on Rails error message display to Japanese localization
[Rails] Function to search and list products from multi-level categories
[rails] error during devise installation
Why you need attr_accessor and why you don't (Thanks to Rails): Rails Tutorial Memorandum--Chapter 9
[Rails tutorial] Cannot deploy to Heroku/Change from hello, world to hola, mundo
Things to remember and concepts in the Ruby on Rails tutorial