[Ruby] RailsTutorial record and memorandum #1 From installation to hello_app deployment + error handling

1 minute read

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

Ruby install

https://railsgirls.jp/install

Rails installation

gem install rails --no-document
rails -v

When specifying the version

gem install rails -v 5.1.6

Create project

Created by specifying the version with the command.

rails _5.1.6_ new hello_app
cd hello_app

Gemfile

Package management file. The package seems to have been downloaded locally. An error occurs if you describe a package that is not local and bundle install. It seems that a package that is not local is downloaded with bundle update.

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 for support. 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

Modify database.yml for Heroku deployment

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

In the initial state, sqlite is used, but Heroku does not support sqlie. Heroku uses postgres, so replace production with 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